LNet TCP OnReceive lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- dhyani · 2011-05-09 16:35 Hello, this is my first post here, so if it's a completely stupid question please be nice This is what i've done so far: 1. Dropped a TLTCPComponent (named as 'TCP') on a form. 2. Connect to server 3. Send a few messages to the server Code: [Select]TCP.SendMessage('Message 1'); TCP.SendMessage('Message 2'); TCP.SendMessage('Message 3'); The server should response to each sent message now, but nothing happens. I'm using the following onReceive Event. Code: [Select]procedure TForm1.TCPReceive(aSocket: TLSocket); var s : string; begin   If TCP.GetMessage(s) > 0 Then     Memo.Append(s); end;  The event doesn't get fired. Well, it doesn't until i disconnect from the server. Then i get a response for the very first message i sent, but not for the other ones. I also tried a timer controlled .GetMessage but that didn't work either. I hope someone can bail me out ---------------------------------------------------------------------- Almindor · 2011-05-09 20:44 1. What OS/Widgetset? (gtk/qt/win32 etc.) 2. Do you wait for the OnConnect before sending? 3. How do you know the server responds (is it a ping server?) 4. How are the messages separated (with pure TCP, each Send <> one receive, you can get it "all in one") ---------------------------------------------------------------------- dhyani · 2011-05-09 21:06 Quote from: Almindor on May 09, 2011, 10:44:23 pm1. What OS/Widgetset? (gtk/qt/win32 etc.) Win32 / Win XP Pro Quote from: Almindor on May 09, 2011, 10:44:23 pm2. Do you wait for the OnConnect before sending? Code: [Select]procedure TForm1.TCPConnect(aSocket: TLSocket); begin   Memo.Lines.Add('Connected...'); end;            When i see the "Connected...' i click a button and send the messages manually. Quote from: Almindor on May 09, 2011, 10:44:23 pm3. How do you know the server responds (is it a ping server?) I actually don't know, but if try Code: [Select]procedure TForm1.TCPConnect(aSocket: TLSocket); begin   Memo.Lines.Add('Connected...');   TCP.SendMessage('CI|REV=2.10|NAME=Test');   TCP.Disconnect; end;  i get 'SI|REV=2.10|NAME=TBMX Client Version 3.4.12-0' as a response - so the connect seems to be successful. But that response isn't received until i disconnect and if i send more messages i only get a response for the first one. Quote from: Almindor on May 09, 2011, 10:44:23 pm4. How are the messages separated (with pure TCP, each Send <> one receive, you can get it "all in one") The messages are separated by #13#10. But most replies are 1:n - i send a command and i get at least one but may be hundreds or even thousands of replies. ---------------------------------------------------------------------- Almindor · 2011-05-10 06:44 Note that memo parses utf-8 text as well as some certain special chars. You might want to try writeln or some other "safer" output method if your data varies. Also try to use UTF8Encode on the received string, or just using a sort of "got something" output. Other than that I don't know. The TCP part of lNet is pretty stable, try it with our own echo server in the examples to see if that works too. ---------------------------------------------------------------------- dhyani · 2011-05-10 08:30 I finally tried it on another machine and it works like a charm. No idea what's going wrong here, but it ain't lNet's fault Thanks for your help anyway!