Forum > Networking and Web Programming

LNet TCP OnReceive

(1/1)

dhyani:
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: ---TCP.SendMessage('Message 1');
TCP.SendMessage('Message 2');
TCP.SendMessage('Message 3');

--- End code ---

The server should response to each sent message now, but nothing happens. I'm using the following onReceive Event.


--- Code: ---procedure TForm1.TCPReceive(aSocket: TLSocket);
var s : string;
begin
  If TCP.GetMessage(s) > 0 Then
    Memo.Append(s);
end; 

--- End code ---

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:
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:

--- Quote from: Almindor on May 09, 2011, 10:44:23 pm ---1. What OS/Widgetset? :) (gtk/qt/win32 etc.)

--- End quote ---

Win32 / Win XP Pro


--- Quote from: Almindor on May 09, 2011, 10:44:23 pm ---2. Do you wait for the OnConnect before sending?

--- End quote ---


--- Code: ---procedure TForm1.TCPConnect(aSocket: TLSocket);
begin
  Memo.Lines.Add('Connected...');
end;             

--- End code ---
When i see the "Connected...' i click a button and send the messages manually.


--- Quote from: Almindor on May 09, 2011, 10:44:23 pm ---3. How do you know the server responds (is it a ping server?)

--- End quote ---
I actually don't know, but if try

--- Code: ---procedure TForm1.TCPConnect(aSocket: TLSocket);
begin
  Memo.Lines.Add('Connected...');
  TCP.SendMessage('CI|REV=2.10|NAME=Test');
  TCP.Disconnect;
end; 

--- End code ---
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 pm ---4. How are the messages separated (with pure TCP, each Send <> one receive, you can get it "all in one")

--- End quote ---
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:
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:
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!

Navigation

[0] Message Index

Go to full version