I have prepared two test projects. There is one TMagIpLog component dropped
on form for each project. One test project is listening its local TCP port
5000. LogProtocol is set to logprotTcpServer. Second test project is trying
to establish a connection to the first test Project using same port number.
Below is my code from second test Project.

procedure TForm9.Button1Click(Sender: TObject);
begin
  MagIpLog1.LogProtocol  := logprotTcpClient;
  MagIpLog1.RemoteHost   := '192.168.1.24';
  MagIpLog1.RemoteIpPort := '5000';
  MagIpLog1.StartLogging;
  if Label2.Caption = 'OK' then begin
    Label3.Caption := 'Connection OK!';
    MagIpLog1.StopLogging;
  end;
end;

procedure TForm9.MagIpLog1LogChangeEvent(Sender: TObject; Socnr: Integer;
  LogState: TLogState);
begin
  if LogState = logstateStart then Label1.Caption := 'Start';
  if LogState = logstateOK then Label2.Caption    := 'OK';
end;

I am seeing that Label3.Caption is not changing at all. It displays 'Label3'
always. On the other hand, I read 'Start' and 'OK' texts on relevant
components. So, MagIpLog is connecting to other test project. However,
connection is, I think, sync. Is there a way to make It async? As you
indicated earlier, async connection will solve my problem, in my real code.

Thanks.



-----Original Message-----
From: TWSocket [mailto:twsocket-boun...@lists.elists.org] On Behalf Of Angus
Robertson - Magenta Systems Ltd
Sent: Monday, March 14, 2016 12:32 PM
To: twsocket@lists.elists.org
Subject: Re: [twsocket] Pinging multipe hosts

>   // PING OK. DO DIRECT TCP CONNECTION
>   if not TestClientConnection(ClientIP, Err) then begin
>     Result := '***ERROR: Client TCP connection fail.';

If you really want to do these tests from the server, this needs to become
async.  

You create an array of TWSocket or TMagIpLog components, either one for each
client you are going to test or a pool (which is more complicated) setting
the Tag to ClientUUID, then you put all your success or fail code in the
OnSessionConnected and OnSessionClosed events.  

Using an array of TMagIpLogs in client mode is easiest, since it already
contains threaded ping to test the connection before an open attempt is
made, you need a single event onLogChangeEvent and to test LogState. 

Angus

--
To unsubscribe or change your settings for TWSocket mailing list please goto
http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to