> See any other obvious issues? Any problem calling Free
> immediately after Close in FreeTelnetClient?

Probably. ICS is asynchronous. It means methods are just request to do some 
operation: the operation is started, you get control back immediately while 
the request is executed in the background. Programming sequentially with 
that behaviour is problematic. You should use the events to do the next 
operation when the previous one is done. See the FAQ on the wiki. There is 
an article about async programming.

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be



----- Original Message ----- 
From: "Mike Lenox" <mle...@ezriver.com>
To: "ICS support mailing" <twsocket@elists.org>
Sent: Friday, May 01, 2009 12:44 PM
Subject: [twsocket] Telnet Client


> More info concerning my original problem which is ...
>
> My application uses a TTnCnx client object to connect (hundreds of times
> per day) to a remote device to retrieve data. On rare occasions the pair
> seem to get stuck in a connected state and stay there indefinitely.
>
> The normal procedure is to call SendMsg which calls Connect.
> OnConnection, write the outgoing message. When a response is received,
> call ClosePort. If no response, MsgTimeout.
>
> {As I write this I see one problem, I don't call Close in the timeout
> procedure. Yet, after several failures, I would still call
> NewTelnetClient which I would expect to get me out of the hung state}
>
> See any other obvious issues? Any problem calling Free immediately after
> Close in FreeTelnetClient?
>
> Mike
>
>
>
>
>
>
> procedure TTLS350E.SendMsg(Msg: string);
> begin
>  try
>    if assigned(TelnetClient) then
> begin
>      TxTCPBuffer := Msg;
>      if TelnetClient.IsConnected = True then begin { connection is
> already active }
>        WriteToTelnet(Msg);
>      end else begin                     { got to get a connection }
>        TelnetClient.Connect;
>      end;
>    end;
>  except
>    ShowNewMessage( 'Exception handled in TCP SendMsg');
>  end;
> end;
>
> procedure TTLS350E.ClosePort;
> begin
>  TelnetClient.Close;
> end;
>
> procedure TTLS350E.MsgTimeout(Sender: TObject);
> begin
>  inc(PortRebuildCount);
>  if PortRebuildCount >= TLS350_TIMEOUTS_RESET then begin
>    PortRebuildCount := 0;
>    NewTelnetClient;
>  end;
> end;
>
> procedure TTLS350E.FreePort;     // This should only be called from 
> Destroy
> begin
>  FreeTelnetClient;
> end;
>
> procedure TTLS350E.FreeTelnetClient;
> var
>  tmpTelnet: TTnCnx;
> begin
>  if assigned(TelnetClient) then begin    // if TCP client exists, kill it
>    tmpTelnet := TelnetClient;
>    tmpTelnet.Close;
>    tmpTelnet.Free;
>    TelnetClient := nil;
>  end;
> end;
>
>  // The following function is called only after multiple
>  // message failures.
>                                         // build a new Telnet object
> procedure TTLS350E.NewTelnetClient;
> begin
>  FreeTelnetClient;
>  TelnetClient := TTnCnx.Create(Application.MainForm);
>  TelnetClient.OnDataAvailable := TnCnxDataAvailable;
>  TelnetClient.OnSessionClosed := TnCnxSessionClosed;
>  TelnetClient.OnSessionConnected := TnCnxSessionConnected;
>  TelnetClient.Port := IntToStr(MyConfig.GetPort);
>  TelnetClient.Host := MyConfig.GetIP;
> end;
>
> -- 
> 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