Code example for ServerSocket

Methods: accept, close, setSoTimeout

0
    } 
 
    public void test_accept() throws IOException { 
        int portNumber = Support_PortManager.getNextPort();
 
        ServerSocket newSocket = new ServerSocket(portNumber);
        newSocket.setSoTimeout(500);
        try { 
            Socket accepted = newSocket.accept();
            fail("SocketTimeoutException was not thrown: " + accepted);
        } catch(SocketTimeoutException expected) {
        } 
        newSocket.close();
 
        ServerSocketChannel ssc = ServerSocketChannel.open();
        ServerSocket ss = ssc.socket();
 
        try { 
            ss.accept();
            fail("IllegalBlockingModeException was not thrown."); 
        } catch(IllegalBlockingModeException ibme) {