Recent

Author Topic: LNet TCP OnReceive  (Read 8423 times)

dhyani

  • Newbie
  • Posts: 5
LNet TCP OnReceive
« on: May 09, 2011, 06:35:08 pm »
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

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: LNet TCP OnReceive
« Reply #1 on: May 09, 2011, 10:44:23 pm »
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

  • Newbie
  • Posts: 5
Re: LNet TCP OnReceive
« Reply #2 on: May 09, 2011, 11:06:39 pm »
1. What OS/Widgetset? :) (gtk/qt/win32 etc.)

Win32 / Win XP Pro

2. 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.

3. 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.


4. 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

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: LNet TCP OnReceive
« Reply #3 on: May 10, 2011, 08:44:32 am »
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

  • Newbie
  • Posts: 5
Re: LNet TCP OnReceive
« Reply #4 on: May 10, 2011, 10:30:14 am »
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!

 

TinyPortal © 2005-2018