[En-Nut-Discussion] Timing and Receiving Data Problem for TCPServer

John Day johnday at wordsnimages.com
Wed Jan 31 18:54:03 CET 2007


At 05:30 AM 1/31/2007, you wrote:
>Hi, Thiago:
>
>I just would like to make a little precision. TCP packets always arrive in
>the same order they were delivered.

In fact not so. Whilst the ideal and efficient 
way is to have TCP handle everything in order it 
is not a requirement. TCP has the sequencing 
mechanism built in to it precisely so it can 
handle out of sequence arrivals. This apper: 
http://www.imconf.net/imw-2002/imw2002-papers/197.pdf 
is an interesting one on just what can happen in 
a non-monodic TCP environment. Any network which 
suffers packet los is likely to experience these problems.

John


>  On the other hand, it's UDP which
>doesn't make any warranty about this issue (packets can be lose or arrive in
>a different order).
>
>Best regards,
>
>
>Jose Vicente.
>
>
>-----Mensaje original-----
>De: en-nut-discussion-bounces at egnite.de
>[mailto:en-nut-discussion-bounces at egnite.de] En nombre de Thiago A. Corrêa
>Enviado el: martes, 30 de enero de 2007 18:57
>Para: Ethernut User Chat (English)
>Asunto: Re: [En-Nut-Discussion] Timing and Receiving Data Problem for
>TCPServer
>
>Hi,
>
>     I'm sorry if I am wrong, but it seams from the description like a common
>misconception about TCP streams. TCP is not packet oriented, it's a stream.
>There is no guarantee that you will be able to read all the data you want in
>a single read (or NutTcpReceive) call. So you must do subsequent calls. 5000
>bytes is larger than the ethernet MTU, so it will be split in at the very
>least 3 ethernet frames which can arrive in distict times and even out of
>order. Of course this applies to not only ethernut, but anything using TCP.
>     Instead of inserting a delay, which in many cases can be suficient but
>also may not in others, you should check for the amount of data you
>received, and if it isn't enought, keep reading until you get it, or you get
>a -1, which means the connection was lost.
>
>     So, something similar to:
>
>int cnt = 0;
>int index = 0;
>while ( cnt < 5000 )
>{
>if ( cnt = NutTcpReceive( socket, buffer + i, 5000 - i ) < 0 )
>     break; // lost connection
>i += cnt;
>}
>
>instead of simply NutTcpReceive( socket, buffer, 5000 ).
>
>Regards,
>    Thiago A. Correa
>
>On 1/30/07, MUHAMMAD AZEEM AZAM <muhammadazeemazam786 at yahoo.com> wrote:
> >
> > Hi
> > I
> > have to receive data from microcontroller.
> > Microcontroller is my server.
> > I have a TCP client (Blocking) on PC.
> > I have a program that have several buttons.
> >
> >   when i press one button my client(button has both send and receive
> > functions)
> > a) sends data to microcontroller.
> > b) microcontroller compares it and then process the request.
> > c) if the process is send data back to client it sends me data.
> >
> >   Now the problem is that when i have to receive 5000 Bytes of data, i
> > Receive only 536 Bytes.
> > when i use "Sleep(5000)" before Receive function  then i get all the data.
> > but this delay is too much for me.
> >
> >   From micrcontroller i am sending the whole (both these techniques)
> > a) array of 5000 Bytes
> > b) buffer using malloc of 5000 Bytes.
> >   does anybody has idea how can i solve this problem
> >
> >   Thanks in Advance for Help
> > Bye
> >
> >
> >
> > ---------------------------------
> > It's here! Your new message!
> > Get new email alerts with the free Yahoo! Toolbar.
> > _______________________________________________
> > http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> >
>_______________________________________________
>http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>
>_______________________________________________
>http://lists.egnite.de/mailman/listinfo/en-nut-discussion




More information about the En-Nut-Discussion mailing list