当客服端连接到了服务端(服务端运行了)之后,用客服端的Connected方法可以判断为true。要是连接中服务端退出了。用Connected方法判断值为什么还是为True?请问要怎么判断客服端是否与服务端连接?

解决方案 »

  1.   

    Determines if the peer has gracefully disconnected.
    procedure CheckForGracefulDisconnect(const ARaiseExceptionIfDisconnected: boolean); virtual;Parametersconst ARaiseExceptionIfDisconnected: boolean = trueRaise an exception when the connection is closed. Default value is True.DescriptionCheckForGracefulDisconnect is a procedure used to determine if the connection has closed gracefully.
    CheckForGracefulDisconnect calls ReadFromStack using the value in ARaiseExceptionIfDisconnected and a 1 millisecond timeout to verify that the socket handle is ready to perform a read operation.
    ReadFromStack updates the ClosedGracefully property and performs exception handling as specified in ARaiseExceptionIfDisconnected. 
       try
         IdTCPClient1.CheckForGracefulDisconnect();
       except
         //非正常断开处理
       end;