Lnet TCP sendmessage, 2 packages merged into 1 lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- senglit · 2020-05-12 05:09 Hi, all I got a problem when I used Lnet. I had codes like these in TCP Server side: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Svr.SendMes sage('a'+Chr(9)+'b'+Chr(9)+'c',Svr.Iterator);...Svr.SendMessage('e'+Ch r(9)+'f'+Chr(9)+'g',Svr.Iterator);  On Client side, I had code like thes Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ClntReceive(aSocket: TLSocket); var  s:string;begin  if aSocket.GetMessage(s)>0 then begin   ...  end;end;  The message can be transferred from Server to Client. But sometimes(not always), the ClntReceive is called and I get the s as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  'a'+Chr(9)+'b'+Chr(9)+'c'+'e'+Chr(9)+'f'+Chr(9)+'g' But what I want is that this procedure to be triggered twice and give me 2 strings seperately. How to do it? ---------------------------------------------------------------------- ccrause · 2020-05-12 07:09 AFAIKS Svr.SendMessage takes a string and send it as a stream of characters.  The SendMessage and GetMessage handlers to not implement anything to interpret a stream of characters as Pascal strings.  You have to define your own protocol on top of this if you want to transfer complete string entities.  Note that another behaviour you can see is that a long string gets broken up into separate chunks, so your GetMessage handler have to cater for this possibility too.  It could be as simple as appending a special character (which then cannot be used as part of your message itself) such as CR or LF or both on the server side to delimit the end of a string, then on the client side you save the received data in a buffer, scan from the start of the buffer for the special delimiter. Once delimiter is found, move data from start to just before delimiter to your final string. For a robust implementation consider the following cases in your code: * A string gets chopped up into several fragments * A string can be transferred as a complete packet (message) * A packet (message) can contain a string + a fragment of or more than one string I'm sure there are other TCP/IP components that implement this type of functionality but I haven't done any TCP/IP programming in a very long time. Maybe slightly easier is to implement a ping-pong protocol where the server sends a string + delimiter then wait for the client to acknowledge the message before sending the next message. There are probably lots of ways to implement this, perhaps you should tell us a bit more about your requirements. PS: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Svr.SendMessage('a'+Chr(9)+'b'+Chr(9)+'c',Svr.Iterator);can alternatively be written as:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Svr.SendMessage('a'#9'b'#9'c',Svr.Iterator); ---------------------------------------------------------------------- senglit · 2020-05-14 05:05 Thanks for your reply. After I found this problem, I tried to build a receiving pool on Client side and it works. But I've thought that maybe there is a simple way to set the Lnet components to ensure each string can be received completely and seperately, so I posted this topic. According to your explaination, that's impossible. You helped me to understand the impossibility and I need to enstrong my user-level protocal. And I do not need to waste time on my old idea. Thank you!