Help with lNET OnReceive Event lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- epergola · 2009-06-19 01:00 Hi I have exhausted all searches possibles in vain, so I hope to find some help here. (Found quite a bit on SendMessage, basically nothing on Receive). I have a Lazarus app that communicates via lnet ltcpcomponent with a tcpserversocket (Delphi) on the LAN server. The LTCP component is installed on an lnet_form (LTCP_Form), which is used by several other forms to communicate with the server. I want to do something like this: The client app:   Form1     send_message_to_server(my specs)     the servers returns data (pure string format)     when  the entire response from the server is captured on the     OnRececive event of the TLCP, fill up a grid in Form2,     Form2.showmodal. so i try to put a function in Form1, something like this:   ret_string:= LTCP_Form.process(myspecs); //this should                                    //sendmessage(myspecs) and return                           //in ret_string the Result of ONReceive   if ret_string <> '' then begin     Form2.fillgrid(ret_string);     form2showmodal;   end; I know (more or less) how to ensure that 'myspecs' is sent completely in the  SendMessage on the TLCP_Form. My problem is with: HOW do I know that  ret_string is the complete message returned from the remote server? In my test, it appears that ret_string is almost always still empty at that point, because ON Receive has not been triggered yet. How do I ensure that I get the WHOLE message retrieved by OnReceive before I proceed with   Form2.fillgrid()? I had thought of making the process() function (inside TLCP_Form) something like this:    SendMessage (My specs);    LTCPOnReceive;  // call the onreceive, which will go in loop until                           // the entire message is red,and ONLY then                           // the next linewill execute and returns control                          //  to Form1.    Result := receive_message; //ok now return, make possible                                         // Form2.fillgrid() But I have 2 problems: 1.LTCPOnReceive takes an argument asocket. What can I pass as      asocket? The LTCPComponent does not have a 'asocket' member. 2.How do  I ensure that the OnReceive event does not terminate      until the WHOLE message from the remote server TCP server    has been read (the messages from the server are all    pure ascii strings terminating with 'END:'. I would greatly appreciate any help. ---------------------------------------------------------------------- Michael · 2009-07-02 22:19 There is a limit to the size of the data that the socket will receive at once, I don't know how large it is.  You will need to make sure your OnReceive procedure appends its data to your buffer until you find the 'END:' terminator indicating that the data transmission is complete Code: [Select]//this would be a sockets OnReceive procedure procedure TfrmMain.tnSocketReceive(aSocket: TLSocket); var     sData: String; begin     if (tnSocket.GetMessage( sData ) > 0) then begin         //check to see if the data chuck has the terminator         If ContainsEndOfTransmission( sData ) then begin             //if it does, we are done, append our last chuck and process the global buffer             CompleteTheTransfer( sData );         end else begin             //otherwise, keep appending data to the buffer             AppendToTheBuffer( sData );         end;     end; end;