Board index » delphi » TIdTCPClient splits data into 1024 byte pakets??

TIdTCPClient splits data into 1024 byte pakets??


2006-07-24 04:16:42 AM
delphi8
Hello,
I need to send data pakets of 1400 bytes from a TIdTCPClient to a
TIdTCPServer.
If I send one paket, the server receives two, one with 1024bytes and one
with the rest.
As the data pakets are created by different threads and coming in very fast,
the server sometimes mixes them up and doesn't put the right ones together.
So first I receive two pakets with the small rest and then the two 1024bytes
pakets.
I thought that the max paket size has something to do with the MTU, which is
1500 on both machines. So is there any way to increase the paket size to
more than 1024 bytes?
Or any other easy way to ensure the right pakets are combined?
Thanks
Marc
 
 

Re:TIdTCPClient splits data into 1024 byte pakets??

Hello,
I need to send data pakets of 1400 bytes from a TIdTCPClient to a
TIdTCPServer.
If I send one paket, the server receives two, one with 1024bytes and one
with the rest.
As the data pakets are created by different threads and coming in very fast,
the server sometimes mixes them up and doesn't put the right ones together.
So first I receive two pakets with the small rest and then the two 1024bytes
pakets.
I thought that the max paket size has something to do with the MTU, which is
1500 on both machines. So is there any way to increase the paket size to
more than 1024 bytes?
Or any other easy way to ensure the right pakets are combined?
Thanks
Marc
 

Re:TIdTCPClient splits data into 1024 byte pakets??

"Marc" <XXXX@XXXXX.COM>writes
Quote
I need to send data pakets of 1400 bytes from a TIdTCPClient
to a TIdTCPServer.
Ok so far.
Quote
If I send one paket, the server receives two, one with 1024bytes
and one with the rest.
That is perfectly normal. That is how TCP works in general. The receiver
must be ready to handle that. Indy's servers do so automatically.
Quote
As the data pakets are created by different threads and coming in very
fast
That is a potential problem. Are you synchronizing access to the socket?
If not, then multiple packets will very likely overlap enough other and
corrupt your data. In order for multiple threads to safely send data to a
the same socket, you MUST protect the socket from being accessed by multiple
thread simultaneous. This applies to both reading and writing.
Quote
the server sometimes mixes them up and doesn't put the right ones
together.
Then you are not writing the data to the socket properly in the first place,
or not reading it back properly. Please show your actual code.
Gambit
 

Re:TIdTCPClient splits data into 1024 byte pakets??

"Marc" <XXXX@XXXXX.COM>writes
Quote
Hello,
I need to send data pakets of 1400 bytes from a TIdTCPClient to a
TIdTCPServer.
OK. These 'packets' are discrete data items associated with your client and
server applications, eg. a record of size 1400. Is this right?
Quote
If I send one paket, the server receives two, one with 1024bytes and one
with the rest.
OK. first of all, TCP does not transfer packets, it transfers octet, (byte)
streams. TCP has no concept of any application-layer protocol units or any
sort of reconrd more complex than a byte. If you send 1400 bytes from a
client and make read calls at the connected server, the OS/TCP-stack may
return 1400 bytes in one call, 1 byte in 1400 calls, or anything in between.
It's just a stream of bytes, nothing else is guaranteed. TCP will
concatenate and.or split up your APUs in any way it feels like, merely
guaranteeing that all *bytes*sent will be received in the same order.
Quote
As the data pakets are created by different threads and coming in very
fast,
the server sometimes mixes them up and doesn't put the right ones
together.
TCP has no concept of application-level data structures, only byte streams.
If you have multiple threads sending different Application Protocol Units,
(packets is a very ambiguous term, best not used), along one client<>server
connection, it is up to you to serialise the sends, either by queueing the
APUs to a single thread or using a critical section or similar synchro
operations.
Quote
So first I receive two pakets with the small rest and then the two
1024bytes
pakets.
I thought that the max paket size has something to do with the MTU, which
is
1500 on both machines. So is there any way to increase the paket size to
more than 1024 bytes?
Or any other easy way to ensure the right pakets are combined?
If your application wants to send anything other than a byte-stream, you
have to add your own protocol on top of TCP. This protocol must be able to
cope with a byte-stream as input and generate APUs as output.
I have to admit that I don't quite understand your exact problem. Indy
tends to make it easy to read data items of varying sizes from the input
stream by providing various calls that return data of a given size from Indy
internal buffers. Surely, there is an Indy read call that can take a length
parameter of 1400 and so will always return your complete APU? I don't
like such protocols myself because they cannot recover at all if a malformed
APU is received, eg. some dodgy router somewhere shoves in an extra null at
the end of one APU to make it 1401 bytes long, so stuffing the alignment and
receipt of all subsequent APUs. Nevertheless, some developers persist in
doing fixed-size read calls and, aparrently, keep connections going for
quite some time before blowing up <g>
Rgds,
Martin
 

Re:TIdTCPClient splits data into 1024 byte pakets??

Hello Remy,
thanks for your reply.
I really had an error in my receive routine, now it has been fixed and
everything is working fine.
Marc
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote

"Marc" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>I need to send data pakets of 1400 bytes from a TIdTCPClient
>to a TIdTCPServer.

Ok so far.

>If I send one paket, the server receives two, one with 1024bytes
>and one with the rest.

That is perfectly normal. That is how TCP works in general. The receiver
must be ready to handle that. Indy's servers do so automatically.

>As the data pakets are created by different threads and coming in very
fast

That is a potential problem. Are you synchronizing access to the socket?
If not, then multiple packets will very likely overlap enough other and
corrupt your data. In order for multiple threads to safely send data to a
the same socket, you MUST protect the socket from being accessed by
multiple
thread simultaneous. This applies to both reading and writing.

>the server sometimes mixes them up and doesn't put the right ones
together.

Then you are not writing the data to the socket properly in the first
place,
or not reading it back properly. Please show your actual code.


Gambit


 

Re:TIdTCPClient splits data into 1024 byte pakets??

Hello Martin,
there was some misunderstanding in how to send data by me.
I now changed everything to streams with fixed length and it is working fine.
Thanks
Marc