Code example for Socket

Methods: close, getInetAddress, setSoLinger, setSoTimeout, setTcpNoDelay

0
    } 
 
    void setSocketOptions(Socket socket)
        throws SocketException { 
        if(linger >= 0 ) 
            socket.setSoLinger( true, linger);
        if( tcpNoDelay )
            socket.setTcpNoDelay(tcpNoDelay);
        if( socketTimeout > 0 )
            socket.setSoTimeout( socketTimeout );
    } 
 
     
    void processSocket(Socket s, TcpConnection con, Object[] threadData) {
        // Process the connection 
        int step = 1;
        try { 
             
            // 1: Set socket options: timeout, linger, etc 
            setSocketOptions(s);
             
            // 2: SSL handshake 
            step = 2;
            if (getServerSocketFactory() != null) { 
                getServerSocketFactory().handshake(s);
            } 
             
            // 3: Process the connection 
            step = 3;
            con.setEndpoint(this);
            con.setSocket(s);
            getConnectionHandler().processConnection(con, threadData);
             
        } catch (SocketException se) {
            log.debug(sm.getString("endpoint.err.socket", s.getInetAddress()),
                    se);
            // Try to close the socket 
            try { 
                s.close();
            } catch (IOException e) {
            } 
        } catch (Throwable t) {
            if (step == 2) {
                if (log.isDebugEnabled()) {
                    log.debug(sm.getString("endpoint.err.handshake"), t);
                } 
            } else { 
                log.error(sm.getString("endpoint.err.unexpected"), t);
            } 
            // Try to close the socket 
            try { 
                s.close();
            } catch (IOException e) {
            } 
        } finally { 
            if (con != null) {
                con.recycle();