Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages
Started by Bilgi Sakarya
Mon, 13 Mar 2006 17:23
TIdTCPClient lack of Knowledge
Author: Bilgi Sakarya
Date: Mon, 13 Mar 2006 17:23
Date: Mon, 13 Mar 2006 17:23
53 lines
2825 bytes
2825 bytes
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
Re: TIdTCPClient lack of Knowledge
Author: Remy Lebeau (TeamB)
Date: Mon, 13 Mar 2006 20:26
Date: Mon, 13 Mar 2006 20:26
53 lines
3090 bytes
3090 bytes
"Bilgi Sakarya" <b.sakarya@riskreturn.ch> wrote in message news:4415a914$1@newsgroups.borland.com... > 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(). > 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. > 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(). > 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. > 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. > 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. > 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads