 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bilgi Sakarya Guest
|
Posted: Mon Mar 13, 2006 6:03 pm Post subject: TIdTCPClient lack of Knowledge |
|
|
Hello,
I'm desperately trying to do receive data with TIdTCPClient. (Version 9.0.5)
with BCB2006
The TIdTCPClient has an Intercept of TIdConnectionIntercept and I/O Handler
of TIdIOHandlerSocket.
Now, on a button click I send a request that looks as follows and works
perfectly
STRUCT_SQL sRequest;
sRequest.iMessageType = SQL_REQUEST_ID;
sRequest.lTicket = rand() % 1000000;
sRequest.lTicket = sRequest.lTicket + 999999;
strcpy( sRequest.szSQL, szSQL.c_str() );
tcp_client->WriteBuffer( &sRequest, sizeof( sRequest), true );
the server receives the request and sends the answer. The server is not
programmed by myself and is in use for ages now.
To make sure I there is no proplem with the server we did some tests with a
client in python and it worked just perfectly.
But I have to write that code in BCB 2006.
But in BCB 2006 I get absolutely now events triggered!!
Strange enough, when adding following line of code after the WriteBuffer
Method a get the OnReceive Event triggered!!!!
AnsiString str_line = tcp_client->ReadLn( "\r\n", 1000,
sizeof(STRUCT_STRING_RESULT) );
But here, sometimes it works, some it doesn't. I think I'm missing something
but with that documentation I'm not getting anywhere. First most of the
examples are written for Delphi and handle to basic stuff like sending some
"Hello World" strings.
My problem is, that I'm passing quite large data, that means the size varies
between 1000 and 200000 bytes depending on the request. That means, that I'm
receiving more than one packet.
Can anybody please explain me or give me an idea how I have to do this. What
is also strange, that Indy 9 on BCB6 works totally different.
There the OnWorkBegin, OnWork and OnWorkEnd are triggered. But I'm not
getting the amount of Bytes I'm expecting.
So basically what I would like to know is:
How do I receive large data with Indy Components?
Please, please help.
Thanks
Bilgi |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Mar 13, 2006 9:03 pm Post subject: Re: TIdTCPClient lack of Knowledge |
|
|
"Bilgi Sakarya" <b.sakarya (AT) riskreturn (DOT) ch> wrote in message
news:4415a914$1 (AT) newsgroups (DOT) borland.com...
| Quote: | But in BCB 2006 I get absolutely now events triggered!!
|
That is because there are not supposed to be any events triggered. Indy is
not an event-based library. Its operations are synchronous, not
asynchronous. Simply call ReadBuffer() (or other appropriate reading
method) immediately after calling WriteBuffer().
| Quote: | Strange enough, when adding following line of code after the
WriteBuffer Method a get the OnReceive Event triggered!!!!
|
As well it should be, because that is how Indy is designed to work. You
called a reading method on the connection, so data is read from the socket
at that point in time, and then passed to the Intercept that you have
assigned to perform additional processing on the received data.
If you think that using a TIdConnectionIntercept will give you asynchronous
events, then that is not how Intercepts are to be used.
| Quote: | AnsiString str_line = tcp_client->ReadLn( "\r\n", 1000,
sizeof(STRUCT_STRING_RESULT) );
|
Since you are reading a fixed-length structure, I suggest that you use
ReadBuffer() instead of ReadLn().
| Quote: | My problem is, that I'm passing quite large data, that means the size
varies between 1000 and 200000 bytes depending on the request.
That means, that I'm receiving more than one packet.
|
Indy handles multiple packets internally. All you have to do is tell Indy
how much to read total, and it keeps reading until that amount is received
in full. Which means that you have to know ahead of time how much data is
going to be sent - or - know how the data is begin to be terminated.
| Quote: | What is also strange, that Indy 9 on BCB6 works totally different.
|
No, it does not. Indy 9 is the same in both BCB and BDS.
| Quote: | There the OnWorkBegin, OnWork and OnWorkEnd are triggered.
|
Only in the context of other reading operation. Again, Indy is not an
asynchronous library. You should not be relyiung on events to handle the
connections.
| Quote: | But I'm not getting the amount of Bytes I'm expecting.
|
That is because you are not using Indy properly to begin with.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|