Recent

Author Topic: What's wrong here with synapse blcksock ?  (Read 9561 times)

yanes19

  • New Member
  • *
  • Posts: 36
What's wrong here with synapse blcksock ?
« on: October 23, 2013, 01:15:36 am »
Hi all ,
I'm trying since three days to establish a TCP sockets client/server connection,
I tested many examples and demos (these attached to synapse 4.0 package )
the problem that my server (tested with Telnet ) doesn't recieve any data (Or doesn't process it correctly) , :(
I used the code suggested by ludob HERE :
http://forum.lazarus.freepascal.org/index.php/topic,16590.msg90665.html#msg90665 (with optimization)
please note that I need to connect to exactly One Client
Here's my code :
Code: [Select]
procedure TForm1.StartServerClick(Sender: TObject);
var
  ClientSock: TSocket;
  sock: TTCPBlockSocket;
begin
  sock := TTCPBlockSocket.Create;
  try
    sock.bind('127.0.0.1','5050');
    sock.listen;
    if sock.LastError <> 0 then
      exit;
    while not Application.Terminated do
    begin
      Application.ProcessMessages;//[color=blue]This is to avoid the form to freeze [/color]
      if sock.canread(1000) then
      begin
        ClientSock := sock.accept;
        if sock. lastError = 0 then
          TalkToClient(ClientSock);
      end;
    end;
  finally
    sock.Free;
  end;
end;
Procedure TForm1.TalkToClient(CSock:TSocket);
var
  s: string;
  NSock:TTCPBlockSocket;
begin
   NSock := TTCPBlockSocket.create;
   NSock.Socket:=CSock;
   NSock.GetSins;
   ShowMessage('Client  '+NSock.GetRemoteSinIP +'  connected !'); //   >>>  This works !,  as expected
   with NSock do
      begin
        repeat
          if lastError<>0 then break;
          s := RecvPacket(6000);         // After exectuting this line , s is always empty string 
          Memo1.Append(s);
          if lastError<>0 then break;     // This exits the loop  !!??§§
          SendString(s);
          showMessage(s);
          if lastError<>0 then break;
        until false;
      end;
end;     

Plese help me !
I want to know where are/is the wrong instructions
Thanks in advance !  :) :D
« Last Edit: October 23, 2013, 05:22:52 am by yanes19 »

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: What's wrong here with synapse blcksock ?
« Reply #1 on: October 23, 2013, 10:21:08 am »
Can you run example from synapse demos? Your code looks exactly like echosrv demo from synapse, but synapse demo is using separated threads to deal with sessions, maybe your "one thread" application is blocking something

serbod

  • Full Member
  • ***
  • Posts: 146
Re: What's wrong here with synapse blcksock ?
« Reply #2 on: October 23, 2013, 11:49:08 am »
After
Code: [Select]
s := RecvPacket(6000);put
Code: [Select]
Memo1.Append(LastErrorDesc);
It can help you understand, what is wrong.

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: What's wrong here with synapse blcksock ?
« Reply #3 on: October 23, 2013, 12:48:24 pm »
Code: [Select]
          s := RecvPacket(6000);         // After exectuting this line , s is always empty string 
          Memo1.Append(s);
How do you get the information off an empty result? Maybe the memo isn't updated because your loop consumes all processing time. And two other thoughts: What happens if you apply RecvString()? And is lasterror<>0 after the call?
Lazarus 1.7 (SVN) FPC 3.0.0

yanes19

  • New Member
  • *
  • Posts: 36
Re: What's wrong here with synapse blcksock ?
« Reply #4 on: October 23, 2013, 04:12:26 pm »
Thankyou all for your time  :),

=> $ serbod : This was a nice idea , Now after executing the lines :
Code: [Select]
          s := RecvString(6000);
          Memo1.Append(LastErrorDesc);
The Memo1 shows the  "Connection timed out" Err. Description , But , Why ? , Is 6000 ms are not enough?
Note that the Telnet client and my server program are running on the same machine .

=======================================
=> $ Ocye :
Quote
How do you get the information off an empty result? Maybe the memo isn't updated because your loop consumes all processing time.
I don't think so ,Buddy , I get the information from the debugger and not from from the memo,

Quote
And two other thoughts: What happens if you apply RecvString()? And is lasterror<>0 after the call?
The RecvString() gave the same result ,
==================================
The problem now is in the "Connection timed out", Can any one Tell me why this occurs ?
Regards  ,

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: What's wrong here with synapse blcksock ?
« Reply #5 on: October 26, 2013, 12:51:51 am »
www.CtrlTerm.com has simple Synapse code that works.
Regards,
Paul Breneman
www.ControlPascal.com

 

TinyPortal © 2005-2018