ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have the following code for receiving a message from udpclient
what i want to do is store all the incoming message into a single variable and then process it......for now i am only getting individual message
iam using C in red hat
int main(int argc, char *argv[]) {
int sd, rc, n, cliLen,i;
struct sockaddr_in cliAddr, servAddr;
May I just ask why you are using UDP in that case? If you want a streamed connection, TCP is generally favoured except where very fast latency is important.
There's no easy way to do this; UDP is a packeted protocol. There is nothing to stop a packet becoming corrupted, dropped, incorrectly ordered or even duplicated in transmission, especially on a big or wireless network. TCP is there to solve all of these problems.
Edit: This is not to say that UDP is unreliable; it's just that the standard doesn't guarentee reliable data transfer. Btw, duplicated packets occur when the acknowledgement for a packet gets dropped and so the server (or a router) resends the packet. UDP tends to be very reliable on wired LANs (with switches or crossovers rather than hubs to reduce cross-talk) when there's no other traffic, but if you have several continuous streams at once then you may get into trouble.
If you want to do streamed UDP then (at the most basic level) you need to set up an array for each client you want to accept connections from, and then copy the entire message into an element in the appropriate place in the array. This should be based on the order of transmission, not reception; you normally put a sequence number into the TCP packet as a sort-of header to say where in the array it should go. But be very careful not to overwrite the end of the array, as this is a major security headache.
You can either process the messages when the array gets full, when you receive a special packet marked with an appropriate flag in the message (note that, once transmitted, this packet may arrive none or more times), or after a certain timeout. In any case, be careful not to fill the array without processing it as it may force you to drop further packets, and not to have a half-empty array that will never get processed after the client stops transmitting. (The timeout option is generally safest.)
Don't be tempted to use a variable-length structure to hold the incoming packets, like a linked list, because you'll be very vunerable to packet-flooding attacks that will eat up all your memory.
i have to disagree. everyone has this big fear of udp just because it unreliable. on our local lan i ran tests and only had a drop rate of 0.1% and actually never had any duplicated messages. if your app is for your own personal use then go with your app. plus if you want the whole message and not have to worry about streaming it and knowing its size then udp is the way to go. i still don't understand your problem though. how do you know how many message to stop to process. your question is a little vague of what you want to process or how many messages before you start processing.
Can any one help? As anyone got any working examples of client/server program that
implements a reliable simplex communications protocol using UDP sockets in C.
Design issues!
1. An acknowledgement messages must be sent back to the
sender from a receiver on successful receipt of a message. Further, if the
sender does not receive an acknowledgement within a timeout then the message
should be sent again. An error message to the effect that the remote
host is down or unreachable should be printed if a message is repeatedly sent
and times out without receiving an acknowledgment. Your sending program should also print out the number of packets that were retransmitted at the end of successfully sending a file.
2. There are a number of design options for the implementation of a reliable
simplex communications protocol and your report should briefy describe 2
possible designs.
3. Attempt to measure the performance of the protocol using the
time command when sending from one PC to another. The maximum packet
size should be adjusted from 1 byte upto 64KByte, when a large file residing on the local
disk filesystem (i.e. /tmp) of approximately 10MByte is sent over the link.
You should repeat each experiment a few times to ascertain if the results are repeatable
Fair enough, but my argument with the Lecturer was I have very little knowledge of programming in C. So how does he expect me to put a program together! Hence I asked him as long as I reference working examples and carry out the test on them. i.e. checking reliability of the protocol would that be ok and he said yes!
What langugae are you familar with? I think if you understood the fundementals and could design it in java/your lanugage I could help you port it over to C. I understand this situation since I had to go from object oriented java to C, which was a pain.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.