Board index » delphi » Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

Does Indy TCP/IP server return full strings or only partial? (using ReadLn)


2006-02-24 04:26:18 AM
delphi168
The title is a bit vague so let me be a little bit more descriptive...
I'm using a game engine (Torque) as my client and it has built-in TCP/IP support. I am planning to use the Delphi 6 Indy components (TidTCPServer) and am wondering how to get these two things to interact with each other. What I am concerned about is reading/writing partial strings.
So how does Indy receive data? Does it guarantee full strings to be returned? How can I view data byte-by-byte (for debugging)?
Any other advice on how to code this properly so I don't lose any data over the network?
Thanks.
 
 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

"John Klimek" <XXXX@XXXXX.COM>writes
Quote
So how does Indy receive data?
It reads what you tell it to read, and does not return until the operation
is complete.
Quote
Does it guarantee full strings to be returned?
Yes. Partial data is handled internally.
Quote
How can I view data byte-by-byte (for debugging)?
You can assign one of the Intercept classes to the connection. If your
protocol is text-based, you can use one of the TIdLog... components, for
instance. Or you can write your own Intercept class for custom processing.
Gambit
 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

Thanks for the reply.
What is an intercept class?
My protocol will be text-based (using some sort of *very* basic encryption) so I guess I need to look at TIdLog. Is there any more information on this? I have found TIdLogBase in the help files but thats it...
(by the way, I am using Delphi 6 in case that matters)
Thanks...
"Remy Lebeau \(TeamB\)" <XXXX@XXXXX.COM>writes:
Quote

"John Klimek" <XXXX@XXXXX.COM>writes
news:43fe287a$XXXX@XXXXX.COM...

>So how does Indy receive data?

It reads what you tell it to read, and does not return until the operation
is complete.

>Does it guarantee full strings to be returned?

Yes. Partial data is handled internally.

>How can I view data byte-by-byte (for debugging)?

You can assign one of the Intercept classes to the connection. If your
protocol is text-based, you can use one of the TIdLog... components, for
instance. Or you can write your own Intercept class for custom processing.


Gambit


 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

One more thing...
I put something like this inside of my TIdTCPServer's OnExecute event:
log.write( AThread.Connection.Readln );
However, it seems like as soon as my client sends a character, it is immediately disconnected. Why is that?
Also, how can I tell how many bytes are incoming?
Thanks.
"John Klimek" <XXXX@XXXXX.COM>writes:
Quote

Thanks for the reply.

What is an intercept class?

My protocol will be text-based (using some sort of *very* basic encryption) so I guess I need to look at TIdLog. Is there any more information on this? I have found TIdLogBase in the help files but thats it...

(by the way, I am using Delphi 6 in case that matters)

Thanks...




"Remy Lebeau \(TeamB\)" <XXXX@XXXXX.COM>writes:
>
>"John Klimek" <XXXX@XXXXX.COM>writes
>news:43fe287a$XXXX@XXXXX.COM...
>
>>So how does Indy receive data?
>
>It reads what you tell it to read, and does not return until the operation
>is complete.
>
>>Does it guarantee full strings to be returned?
>
>Yes. Partial data is handled internally.
>
>>How can I view data byte-by-byte (for debugging)?
>
>You can assign one of the Intercept classes to the connection. If your
>protocol is text-based, you can use one of the TIdLog... components, for
>instance. Or you can write your own Intercept class for custom processing.
>
>
>Gambit
>
>

 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

"John Klimek" <XXXX@XXXXX.COM>writes
Quote
However, it seems like as soon as my client sends a character,
it is immediately disconnected. Why is that?
Please show your actual code. My guess would be that an exception is being
thrown.
Gambit
 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

"John Klimek" <XXXX@XXXXX.COM>writes
Quote
What is an intercept class?
Intercepts are components that are designed to analyze the data in real-time
as it is being transmitted/received. Indy uses Intercepts for altering the
data on the fly, such as for encryption and compression, and to log the data
to files for later viewing and playback.
Quote
by the way, I am using Delphi 6 in case that matters
BCB/Delphi 6 ships with Indy 8, which is very old and no longer supported.
You should upgrade to either Indy 9 or 10 instead.
Gambit
 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

I've gotten this fixed... (actually I forgot at the moment what I did yesterday to fix it).
However I have another question...
Can I force Indy to send only ONE packet with my string data?
For example, I want to this send this string to my client:
MOVE 10 200
From what I remember, TCP can split that into two packets (for example, one containing "MOVE 1" and the next packet containing "0 200".
I don't have much control over my client application so I would like to guarantee that only ONE packet gets sent with the full information...
Is this possible?
"Remy Lebeau \(TeamB\)" <XXXX@XXXXX.COM>writes:
Quote

"John Klimek" <XXXX@XXXXX.COM>writes
news:43ff2d36$XXXX@XXXXX.COM...

>However, it seems like as soon as my client sends a character,
>it is immediately disconnected. Why is that?

Please show your actual code. My guess would be that an exception is being
thrown.


Gambit


 

Re:Does Indy TCP/IP server return full strings or only partial? (using ReadLn)

"John Klimek" <XXXX@XXXXX.COM>writes
Quote
Can I force Indy to send only ONE packet with my string data?
No. TCP itself does not work that way.
Quote
For example, I want to this send this string to my client: MOVE 10 200
Then just send that string as-is, ie:
IdTCPClient1.Write('MOVE 10 200');
Quote
From what I remember, TCP can split that into two packets
Yes, and that is perfectly normal behavior. The other party is responsible
for receiving multiple packets when appropriate and recombining them before
then processing the full data. If you are using Indy on the other side,
then all of that is handled transparently for you.
Quote
I don't have much control over my client application
*Every* TCP application has to be written to handle divided packets. If an
application is not written properly, then there is no quarantee for the
integrity of the data.
Quote
so I would like to guarantee that only ONE packet gets sent with the
full information...
There is no way to do that in TCP. The division of the data is at the sole
discretion of the underlying socket stack (WinSock under Windows platforms,
libc under Linux, etc) that directly communicates with the hardware. There
is nothing the socket library that sits on top of the socket stack (Indy in
this case) can do about that. The stack accepts as much data as it can into
its internal buffer, returning to the caller how many bytes were accepted,
and then the stack sends that buffer over the network in the background at
its leisure.
Gambit