Avatar of lloydie-t
lloydie-t
 asked on

LNet TCP client problem

I'm desperate for a bit of help. I am try to create a small app which will send messages to a tcp server.
Problem is the server is not available the main unit should continue, but at the moment it just seems to halt waiting for a connect.
Please have a look at http://pastebin.com/d1662d999 and let me know where I am going wrong
{*********************************************
Data Msg Unit
**********************************************}
 
 
unit datamsg;
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, lnet;
 
type
 
  { TLTCPMsg }
 
  TLTCPMsg = class
   private
    FCon: TLTcp; // the connection
   public
    constructor Create;
    destructor Destroy; override;
    procedure Run(Recvstring : String; Port : word);
  end;
 
 
implementation
 
constructor TLTCPMsg.Create;
begin
  FCon := TLTCP.Create(nil); // create new TCP connection with no parent component
  FCon.Timeout := 100; // responsive enough, but won't hog cpu
end;
 
destructor TLTCPMsg.Destroy;
begin
  FCon.Free; // free the connection
  inherited Destroy;
end;
 
procedure TLTCPMsg.Run(Recvstring : String; Port : word);
var
  s: string; // message-to-send and address
  Sent, conwait: integer;
begin
    conwait := 0;
    if FCon.Connect('localhost', Port) then begin // if connect went ok
      repeat
        FCon.CallAction; // wait for "OnConnect"
        sleep(100);
      until (FCon.Connected) or  (conwait = 3);
            
      if FCon.Connected then begin // if we connected succesfuly
        repeat
          Sent := Fcon.SendMessage(Recvstring);
          Delete(Recvstring, 1, Sent);
          FCon.Callaction; // eventize lNet loop
        until Sent = 0; // try until all data is sent
      end; // if not FQuit
    end; // if Connect
end;
 
 
 
end.
 
 
{**************************************
excerpt of main unit
*************************************} 
 
 
uses
  Classes, SysUtils, ZConnection, ZDataset, lNet , oxounit, inifiles,datamsg;
 
 
procedure TTCPEchoDaemon1.OnRe(aSocket: TLSocket);
var
  s: string;
  n: Integer;
begin
  if aSocket.GetMessage(s) > 0 then begin
    RecvString(s);
    FCon.IterReset;
  end;
end;
 
 
function TTCPEchoDaemon1.RecvString(S2: String): AnsiString;
var
  n : integer;
  Stringtest : String;
begin
    n := 1;
    while n <= Length(S2) do begin
          if S2[n] = LF then begin
          myconverterfunc1:=@CallConv1;
          myconverterfunc1(Stringtest);
          stringtest := '';
          Delete(S2, n, 1);
          Continue;
          end;
    Stringtest := Stringtest+Copy(S2, n, 1);
    inc(n);
    end;
 
end;
 
Function CallConv1 (S1: String): String;
var
SendMSG:TLTCPMsg;
begin
 oxoparse1.PbxGet(RegExpStr1,S1,SiteID1); //If tcp socket is not available I never get past here
 sendMSG := TLTCPMsg.Create;
 sendMSG.Run(S1,4512);
 sendMSG.Destroy;
 writeLn(S1);
end;

Open in new window

Editors IDEsPascal

Avatar of undefined
Last Comment
lloydie-t

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lloydie-t

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy