Code example for ServerSocket

Methods: acceptclosesetSoTimeout

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."); 
Stop searching for code, let great code find you!  Add Codota to your java IDE