Re: Broken TCP/IP packets
- From: Markus Zingg <m.zingg@xxxxxx>
- Date: Sun, 01 Apr 2007 13:49:27 +0200
On 1 Apr 2007 02:48:10 -0700, "Ali" <abdulrazaq@xxxxxxxxx> wrote:
I have a serial device that is using MCU's UART (rs232) for data
transfer, every time my device is suppose to deliver 20 bytes making
it a single transaction. We have a VB and C# app using MSCOMM and it
works perfectly.
Now I have added an Ethernet converter to convert serial data to TCP/
IP packets. It works atleast for half of the time. For the rest of
the problematic half the behavior is very strange, yes, my received
packets are broken in parts. For example I'll receive 20 bytes in tow
transactions like 10 byte for each time. I tried to look at the MCU
UART signal via oscilloscope but the timing was quite consistent.
Can't understand why packets are broken/scattered, any idea?
regards,
ali
Ali
You cannot expect TCP to give you pakets on the remote end the way you
feed them into the system. That's just by design. TCP is a streaming
protocol, and it's up to the senders TCP stack implementation to fill
segments to what ever degree seems good to get a good performance.
That said, the sending part will most likely try to combine your 20
bytes chunks of data into as few segments as possible cause sending
out a segment over the wire is timewise expensive. The Nagle algorithm
will delay sending out segments a tad bit to see if more data arrives
and if so will concatenate your pakets into a single bigger TCP
segment.
So your reciveing end simply must be written so as it keeps on reading
from the TCP stream up until you have 20 bytes, and store excess bytes
it may have read for the next call. This can easily be implemented
with a ring buffer structure and as many calls to recv() as needed.
If you try to circumvent this, you are fighting against TCP and
potential oddities/requierements of the unterlaying network along the
comunication path.
HTH
Markus
.
- Follow-Ups:
- Re: Broken TCP/IP packets
- From: MisterE
- Re: Broken TCP/IP packets
- From: Ali
- Re: Broken TCP/IP packets
- References:
- Broken TCP/IP packets
- From: Ali
- Broken TCP/IP packets
- Prev by Date: Re: Who is working with the SAM9263?
- Next by Date: Re: Nvram write modes and problems (Compiler support)
- Previous by thread: Broken TCP/IP packets
- Next by thread: Re: Broken TCP/IP packets
- Index(es):
Relevant Pages
|