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.