Windows

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • TWSocket

    1 answers - 1303 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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: T);
    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 SessionConnected I send a SendStr command to get some
    data. I read this with the DataAvailable:
    procedure TForm1.icsWSocketDataAvailable(Sender: T; 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
  • No.1 | | 568 bytes | |

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

    procedure TForm1.Button1Click(Sender: T);
    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 !

Re: TWSocket


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 7 =
QUESTION ON "Windows"

EMSDN.COM