The normal way to gracefully close a connection is to call Shutdown(1). 
You'll then receive the OnSessionClosed even when remote part acknowledged 
the close.

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>  if icsWSocket.State  <> wsClosed then
>    icsWSocket.Close;
>
>  if icsWSocket.State = wsClosed then begin
>    icsWSocket.Addr := address.Text;
>    icsWSocket.Port := port.Text;
>    icsWSocket.Connect;
>    Timer1.Enabled := false;
>  end;
> end;

This is not good. Close will do have an immediate effect ! You should use 
the events !

--
Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
http://www.overbyte.be

----- Original Message ----- 
From: "Stefan Blankenagel" <[EMAIL PROTECTED]>
To: "ICS support mailing" <twsocket@elists.org>
Sent: Monday, May 15, 2006 7:34 PM
Subject: [twsocket] TWSocket


> Hi,
>
> I am writing a little program wchich is polling another program using
> TWSocketServer. For testing purposes I press a button which connects to
> the other program:
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>  if icsWSocket.State  <> wsClosed then
>    icsWSocket.Close;
>
>  if icsWSocket.State = wsClosed then begin
>    icsWSocket.Addr := address.Text;
>    icsWSocket.Port := port.Text;
>    icsWSocket.Connect;
>    Timer1.Enabled := false;
>  end;
> end;
>
> In the event OnSessionConnected I send a SendStr command to get some
> data. I read this with the OnDataAvailable:
>
> procedure TForm1.icsWSocketDataAvailable(Sender: TObject; ErrCode: Word);
> var inbuf : string;
> begin
>  inbuf := icsWSocket.ReceiveStr;
>
>  if pos('Status', inbuf) > 0 then
>  begin
>    inbuf := StrAfter(#$FF, inbuf);
>    decode_data(inbuf);
>    icsWSocket.close;
>  end;
> end;
>
> If I got the right data I want to close the connection. It is closed
> then. If I press a second time the button the Connection is closed
> without recieving any data and gives an error code 100053 (Connection
> Aborted). Why dows this event occur ?? Normally a timer should connect
> automatically every 20 seconds and get the status of the other software.
>
> Thanks
>  Stefan
>
> -- 
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://www.elists.org/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be 

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

Reply via email to