Re: Multiple PDUs in UDP Packet?

From: Michael B Allen (mba2000_at_ioplex.com)
Date: 05/20/05


Date: Fri, 20 May 2005 16:52:30 -0400

On Fri, 20 May 2005 13:08:18 +0200, Måns Rullgård wrote:

> Michael B Allen <mba2000@ioplex.com> writes:
>
>> Is it ok to send multiple Protocol Data Units in one UDP packet?
>>
>> For example, would it be normal (or wise) to encode 3 DNS requests into
>> a buffer and then send the entire buffer with one call to sendto(2)?
>>
>> I'm writing some generic message multiplexing code and want to know if
>> I need to treat UDP (sendto) different from TCP (write).
>
> It all depends on what the receiving end is expecting. Are you
> dealing with a standard protocol, or something of your own invention?

I'm trying to be generic so it could be a standard protocol or it could
be custom. As it is I have buffers into which I encode messages. These
buffers are then "written" to sockets. The question is - if I encode
multiple messages into a single buffer can they all be sent with a single
call to write(2)/sendto(2)?

For TCP the answer is absolutely yes because any good protocol decoder
will have to deal with the scenario where some packets are coalesced due
to congestion, client/server speed differential, etc. Thus the decoder
must know how to determine the PDU boundry.

But with UDP this will not work (I don't think - this is what I'm asking)
because the packet *is* the PDU so a call to sendto(2) corresponds
directly to one recvfrom(2) at the other end (minus lost packets). Thus
if I try to sendto(2) a buffer containting 3 PDUs, the other end will
think it's one PDU and probably choke.

So, my message multiplexing code must behave differently depending on
wheather or not the socket is UDP or TCP. If it's TCP I can just write
whatevers in the buffer. For UDP I must either keep track of the PDU
boundies so I can ensure only one PDU is used with each call to sendto(2)
or ensure that the buffer is flushed with sendto(2) before encoding
another message.

Mike



Relevant Pages

  • Re: port=1026&reason=ICMPsent
    ... > Actually ICMP is a layered protocol the UDP protocol in question is a ... in the payload of an ICMP ... with a payload indicating it was in response to a UDP packet? ...
    (alt.computer.security)
  • Re: port=1026&reason=ICMPsent
    ... Not sure now about the UDP, here is the .enc file decode for one of the ... Time delta from previous packet: ... Fragment offset: 0 ... Protocol: ICMP ...
    (alt.computer.security)
  • Re: Losing UDP packets with MFC Sockets
    ... a call to ReceiveFrom method is done. ... 2.- A CByteArray object is creating with 'new' with data received from buffer. ... class to indicate the packet arrival. ... CPU load is not the main culprit in UDP ...
    (microsoft.public.vc.mfc)
  • Re: WinSock Question
    ... TC protocol and have a rudimentary multi-client setup working. ... additional validation or acknowledgement this may slow things ... Both TCP and UDP have a field for checksum, ... it's possible for the packet to be ...
    (comp.lang.basic.visual.misc)
  • Re: Python sockets UDP broadcast multicast question??
    ... I'm new to socket programming so please bare with me. ... So my question is how can I receive a continuous stream of UDP packets ... The UDP protocol is defined 'unreliable' because it cannot guarantee ... So, first of all, if you cannon tolerate packet loss, consider ...
    (comp.lang.python)