Packet Data Question

Started by
14 comments, last by genovov 24 years, 2 months ago
Well, thanks to all who replied. I think I've got all the information I need to proceed with this part of the network coding : )

I've got a new question though. I've read in numerous places, that the UDP/IP protocol offers faster transfer times (smaller headers, and no packet ordering or guarantee of reciept) than TCP/IP. I've read that 'packet' loss can be as high as ~20%. My question is what exactly determines what data will be in a 'packet'. Does every call to write() on a socket create a new packet? I've heard there is an algorithm (forget the name) that is used to buffer TCP/IP data for optimum efficency. Is this algorithm also applied to UDP/IP transfers? I ask because I want to know if I have to deal with cases where I will recieve only the start or the end of a message that I've sent, or if i can insure that each of my networking messages exist in one and only one packet.

-g

Advertisement
I've been working on a small client/server multiplayer game in linux, with the intent to porting the client to other os's at a later date. Keeping portablity in mind, does anyone have any suggestions on how to send data between the client and the server. I was initially sending binary data, thinking that it would make for smaller packets, but then realized that writing sizeof(foo) bytes on one machine and reading sizeof(foo) bytes on another machine wouldn't work, if their internal representations are different (alphas for instance). Also, am I correct in assuming that endian-ness would also render this method useless, without conversion to network byte order when sending and recieving?

The only other option left seems to be converting all data into ascii text strings, sending it, and then converting the text back into integers/floats ect. Would printf()/scanf() do the trick? Does anyone know how this is done 'in the real world'?

Thanks a bunch

[This message has been edited by genovov (edited November 17, 1999).]

UDP is simply a packet on the wire, and doesn't perform any sort of reliability or flow control (Nagle's algorithm). UDP packet headers may be simpler, but can't take advantage of TCP header compression.

UDP packets are usually sent with sendto() and recv'd with recvfrom(), so that you can specify the remote address -- since there is no actual connection between the hosts. Each call to sendto() sends a single packet, and each call to recvfrom() reads one in (if available).

UDP is nice if you want fine control over the retry and flow control algorithms (games have different needs than FTP software), but if you aren't network-savvy, then it's easy to ruin your performance instead of improving it.

Matt Slot / Bitwise Operator / Ambrosia Software, Inc.
I''m still a bit confused . Maybe a quick example will clarify my question.

Two processes are sending packets to each other, with open UDP sockets. Process1 has sent 3 16-byte packets since Process2 last called recvfrom(). Assuming no packets were droped, and that all three have arrived, what will happen when Process2 calls recvfrom again, with a maxlen parameter of 48(3x16)?

Will it read in 16 bytes(1 packet), or 48(all three)?

Thanks,

-genovov
recvfrom() will only return 1 UDP packet, no matter how many are queued up. It also will truncate the packet if the buffer you pass is too small -- you lose the rest of the packet.

recv() will try to fill the buffer you pass it with TCP data, regardless of how it was sent (1 large packet or 50 small ones). It''s a "stream" format, so all the data just runs together, and it''s up to you to accumulate and break it into messages.
Matt Slot / Bitwise Operator / Ambrosia Software, Inc.
Thanks for your quick response

-genovov

This topic is closed to new replies.

Advertisement