Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   problems with windows sockets (http://www.velocityreviews.com/forums/t742043-problems-with-windows-sockets.html)

GilNajera 01-14-2011 03:34 PM

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.

Tom St Denis 01-14-2011 03:46 PM

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

Pavel Borzenkov 01-14-2011 04:05 PM

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


Tom St Denis 01-14-2011 06:57 PM

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

David Resnick 01-14-2011 09:29 PM

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

Michael Angelo Ravera 01-18-2011 08:36 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57