Reputation: 26756
I've used TCP for many things over the years and understand it pretty well. I now have a requirement to use UDP.
Short version: A server allows a small number of clients (5-10) to connect. The server is running a simulation. Clients should be able to update parameters for the simulation and see (a subset) of the simulation results.
In this instance, timing (when the parameters change) is important and the delay between the client requesting a change and it being implemented must be as low as possible.
I've been doing a lot of reading and I'm still not "getting it".
Can someone please confirm/deny my understanding...
So... If I want to send (say) 800 bytes of data from the client to the server, I need to:
For messages going in the other direction, I need to do exactly the same in reverse.
I can't help feeling I'm missing something and don't quite understand the implications of a packet fragmenting. Can someone please clarify / point to a better resource?
Upvotes: 3
Views: 5319
Reputation: 310840
- A datagram is stored inside a single packet
Not necessarily.
- The largest payload I can reliably send is 506 bytes (576 MTU - 60 IP header - 8 UDP header)
Incorrect. The IP header is 20 bytes, not 60, so the total header is 28 bytes. That leaves you 576-28=548, but the number usually bandied around is 534.
- Sending more than that may cause fragmentation
Yes.
- Fragmentation isn't handled at a lower level and would require me to recombine datagrams (Not sure about this - if it's handled automatically, why do I care about fragmentation?)
Incorrect. Fragmentation is handled completely at the IP level. The problem with fragmentation in UDP is that there is no ACK/retransmit mechanism for lost fragments, so one lost fragment means the entire datagram is lost. What you see is either an entire UDP datagram or nothing.
- I need to implement my own ACK/Throttling mechanism
Yes. A simple ACK/retry scheme is given in W.R. Stevens, Unix Network Programming, vol I.
Upvotes: 6
Reputation: 24847
A datagram is stored inside a single packet
No.
The largest payload I can reliably send is 506 bytes (576 MTU - 60 IP header - 8 UDP header)
'Reliably send' means different things to different levels.
Sending more than that may cause fragmentation
Economical with the truth.
Fragmentation isn't handled at a lower level and would require me to recombine datagrams (Not sure about this - if it's handled automatically, why do I care about fragmentation?)
Depends on what level you are at. At app level, datagrams are either received in their entirety, or not at all.
Sub-questions: Too broad, but it sounds like you should be using TCP instead.
Upvotes: 2