Code example for ServerSocketChannel

Methods: acceptsocketisBlocking

0
            // OK. 
        } 
    } 
 
    public void testAccept_Block_NoConnect() throws IOException { 
        assertTrue(this.serverChannel.isBlocking());
        ServerSocket gotSocket = this.serverChannel.socket();
        gotSocket.bind(localAddr1);
        // blocking mode , will block and wait for ever... 
        // so must close the server channel with another thread. 
        new Thread() {
            public void run() { 
                try { 
                    Thread.sleep(TIME_UNIT);
                    ServerSocketChannelTest.this.serverChannel.close();
                } catch (Exception e) {
                    fail("Fail to close the server channel because of"
                            + e.getClass().getName());
                } 
            } 
        }.start();
        try { 
            this.serverChannel.accept();
            fail("Should throw a AsynchronousCloseException");
        } catch (AsynchronousCloseException e) {
            // OK. 
        } 
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE