![]() |
problems with windows sockets
Hi everyone!
I have an application that communicates 2 computers using tcp sockets (winsocks). The most of the time it works fine, but some packets are received as 1 when they was sent as 2 or 3. I mean, I execute two or three send commands and receive all the data in one single packet. The packets are sent every 200 ms (Naggle's algorithm is disabled) and there is an independent thread receiving on the other side's application. When a packet is received it is processed immediately, after that, the receiving is resumed. I'm not an expert in networking, can anybody tell me why is this happening, and how can I solve it. Thanks in advance. |
Re: problems with windows sockets
On Jan 14, 10:34*am, GilNajera <gilnaj...@gmail.com> wrote:
> Hi everyone! > > I have an application that communicates 2 computers using tcp sockets > (winsocks). The most of the time it works fine, but some packets are > received as 1 when they was sent as 2 or 3. I mean, I execute two or > three send commands and receive all the data in one single packet. > > The packets are sent every 200 ms (Naggle's algorithm is disabled) and > there is an independent thread receiving on the other side's > application. When a packet is received it is processed immediately, > after that, the receiving is resumed. > > I'm not an expert in networking, can anybody tell me why is this > happening, and how can I solve it. TCP is a streaming protocol not a datagram one. So it can merge packets so that a single recv() can read multiple send()'s worth of data. If you want datagram service use UDP. Tom |
Re: problems with windows sockets
Hi,
On 2011-01-14, Tom St Denis <tom@iahu.ca> wrote: > On Jan 14, 10:34?am, GilNajera <gilnaj...@gmail.com> wrote: >> Hi everyone! >> >> I have an application that communicates 2 computers using tcp sockets >> (winsocks). The most of the time it works fine, but some packets are >> received as 1 when they was sent as 2 or 3. I mean, I execute two or >> three send commands and receive all the data in one single packet. >> >> The packets are sent every 200 ms (Naggle's algorithm is disabled) and >> there is an independent thread receiving on the other side's >> application. When a packet is received it is processed immediately, >> after that, the receiving is resumed. >> >> I'm not an expert in networking, can anybody tell me why is this >> happening, and how can I solve it. > > TCP is a streaming protocol not a datagram one. So it can merge > packets so that a single recv() can read multiple send()'s worth of > data. > > If you want datagram service use UDP. I think this is not a very good advice, since UDP doesn't guarantee packets' delivery. A better solution is to develop a communication protocol that includes a header for every data packet and put the data size into this header. -P > > Tom |
Re: problems with windows sockets
On Jan 14, 11:05*am, Pavel Borzenkov <pa...@devio.us> wrote:
> Hi, > > On 2011-01-14, Tom St Denis <t...@iahu.ca> wrote: > > > > > > > > > > > On Jan 14, 10:34?am, GilNajera <gilnaj...@gmail.com> wrote: > >> Hi everyone! > > >> I have an application that communicates 2 computers using tcp sockets > >> (winsocks). The most of the time it works fine, but some packets are > >> received as 1 when they was sent as 2 or 3. I mean, I execute two or > >> three send commands and receive all the data in one single packet. > > >> The packets are sent every 200 ms (Naggle's algorithm is disabled) and > >> there is an independent thread receiving on the other side's > >> application. When a packet is received it is processed immediately, > >> after that, the receiving is resumed. > > >> I'm not an expert in networking, can anybody tell me why is this > >> happening, and how can I solve it. > > > TCP is a streaming protocol not a datagram one. *So it can merge > > packets so that a single recv() can read multiple send()'s worth of > > data. > > > If you want datagram service use UDP. > > I think this is not a very good advice, since UDP doesn't guarantee packets' > delivery. A better solution is to develop a communication protocol that > includes a header for every data packet and put the data size into this > header. While true, it's not of practical use. I have never, ever, with all my lab work, ever seen a UDP packet dropped or lost. But ya, if he wants to do things properly he should either put headers on his TCP traffic or do some form of UDP ACK/NAK. Tom |
Re: problems with windows sockets
On Jan 14, 1:57*pm, Tom St Denis <t...@iahu.ca> wrote:
> On Jan 14, 11:05*am, Pavel Borzenkov <pa...@devio.us> wrote: > > > > > Hi, > > > On 2011-01-14, Tom St Denis <t...@iahu.ca> wrote: > > > > On Jan 14, 10:34?am, GilNajera <gilnaj...@gmail.com> wrote: > > >> Hi everyone! > > > >> I have an application that communicates 2 computers using tcp sockets > > >> (winsocks). The most of the time it works fine, but some packets are > > >> received as 1 when they was sent as 2 or 3. I mean, I execute two or > > >> three send commands and receive all the data in one single packet. > > > >> The packets are sent every 200 ms (Naggle's algorithm is disabled) and > > >> there is an independent thread receiving on the other side's > > >> application. When a packet is received it is processed immediately, > > >> after that, the receiving is resumed. > > > >> I'm not an expert in networking, can anybody tell me why is this > > >> happening, and how can I solve it. > > > > TCP is a streaming protocol not a datagram one. *So it can merge > > > packets so that a single recv() can read multiple send()'s worth of > > > data. > > > > If you want datagram service use UDP. > > > I think this is not a very good advice, since UDP doesn't guarantee packets' > > delivery. A better solution is to develop a communication protocol that > > includes a header for every data packet and put the data size into this > > header. > > While true, it's not of practical use. *I have never, ever, with all > my lab work, ever seen a UDP packet dropped or lost. > > But ya, if he wants to do things properly he should either put headers > on his TCP traffic or do some form of UDP ACK/NAK. > > Tom RTP (media transport typically used for VoIP) is generally sent using UDP. I've seen quite a few cases where there was packet loss in real telephony networks, so I'd say it is a practical issue. Of course, at 50 packets per second losing one here or there doesn't actually degrade audio quality (loss of 20 milliseconds of audio data matters not at all). But still, any design that requires reliability shouldn't use UDP unless you build a protocol to enable retransmission... -David |
Re: problems with windows sockets
On Jan 14, 7:34*am, GilNajera <gilnaj...@gmail.com> wrote:
> Hi everyone! > > I have an application that communicates 2 computers using tcp sockets > (winsocks). The most of the time it works fine, but some packets are > received as 1 when they was sent as 2 or 3. I mean, I execute two or > three send commands and receive all the data in one single packet. > > The packets are sent every 200 ms (Naggle's algorithm is disabled) and > there is an independent thread receiving on the other side's > application. When a packet is received it is processed immediately, > after that, the receiving is resumed. > > I'm not an expert in networking, can anybody tell me why is this > happening, and how can I solve it. > > Thanks in advance. If I understand your problem correctly, the usual solution is to prefix each logical packet with a size word of whatever length you like (2 or 4 bytes is fairly common). The other common solution is to send all logical packets as the same fixed size or to make them self- described in length somehow( terinating character for instance). You have to pick one of these. |
| All times are GMT. The time now is 09:33 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.