Re: UDP packets greater than 510 bytes clipped
Re: UDP packets greater than 510 bytes clipped
- Subject: Re: UDP packets greater than 510 bytes clipped
- From: Vincent Lubet <email@hidden>
- Date: Tue, 21 Jun 2005 11:20:01 -0700
MSG_PEEK works well when the packet has some kind of header with a
length field -- not all UDP based protocols have it.
Another solution is to use the socket option SO_NREAD to get the
length of the first packet that sits in the receive socket buffer.
Often you can just receive data into a buffer big enough to fit the
largest packet that can be transmitted over the particular UDP based
protocol.
Vincent
On Jun 21, 2005, at 10:58 AM, Josh Graessley wrote:
How are you reading the data? If you don't read the whole packet
contiguously, the remainder of the packet is discarded. I think you
can use MSG_PEEK to grab the first few bytes before reading the
whole thing.
If this isn't the problem, it is odd that you would get part of the
packet. The stack will either put the whole packet together and
pass it to you or discard it if something goes wrong. There's no
half way.
-josh
On Jun 21, 2005, at 2:02 AM, Heath Raftery wrote:
G'day list,
I've been playing with UDP transmission in my Cocoa app for a few
days. My intention is to have UDP provide fast, unreliable, raw
data transfer to back up the current TCP messaging framework I
have working. At first sendto() returned EMSGSIZE's, so I now
check getsockopt(SO_SNDBUF) first and limit outgoing packets to
that size. I no longer get EMSGSIZE, and packet sniffing seems to
show the correct thing happening. That is, the entire packet is
sent out, but in IP fragments of about 1500 bytes. However the
receiving host does not get all the data.
From what I've read, IP should fragment the packets to the MTU of
the medium, and reassemble them at the other end. But the
reassembly doesn't appear to be happening! In fact, on the
receiving side I only get about 510 bytes of each packet, which
destroys the data. On the advice I read in a few different places,
I limited the packet size to 548 bytes, since apparently that
guarantees I wont get segmentation. That didn't help - I still
only received about 510 bytes.
In desperation I limited the packet size to 400 bytes, and
everything seems to work well - except that I'm sending out a lot
of packets of course!
The network architecture I was playing with was:
client <-> airport <-> server <-> localhost <-> client
SO_SNDBUF = 9216
SO_RCVBUF = 42080
I'm using the socket, bind and sendto calls to establish and send
UDP data, and NSFileHandle's readInBackgroundAndNotify to read.
Would I be right in discovering
readToEndOfFileInBackgroundAndNotify does not apply to UDP?
Can anyone suggest why I can't get more than about 510 bytes
through via UDP? Does anyone have any relevant resources to
suggest to learn more about UDP on OS X using Cocoa? I've read a
bit of general UDP information (such as <http://www.kmutt.ac.th/
knowledge/programming/c/unix_socket/faq/unix-socket-faq-5.html>)
but haven't found much at all that deals with Cocoa or OS X in
particular.
Heath
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden