Code example for Socket

Methods: isClosed, isConnected

0
        mSocket.setSoTimeout(timeoutMilliseconds);
    } 
 
    public boolean isOpen() { 
        return (mIn != null && mOut != null && 
                mSocket != null && mSocket.isConnected() && !mSocket.isClosed());
    } 
 
    /** 
     * Close the connection.  MUST NOT return any exceptions - must be "best effort" and safe. 
     */ 
    public void close() { 
        try { 
            mIn.close();
        } catch (Exception e) {
            // May fail if the connection is already closed. 
        } 
        try { 
            mOut.close();
        } catch (Exception e) {
            // May fail if the connection is already closed.