Java 8 ServerSocketChannel - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ServerSocketChannel class.

This code example shows how to use the following methods: sleep, register, socket, configureBlocking
 
	public static void main(String[] args) {
		try { VocabServer v = new VocabServer(4444);
		Thread t = new Thread(v);
		t.start();
		try {Thread.sleep(10000); } catch (Exception e ) {}
		v.stopServer();
		} catch (IOException e) { e.printStackTrace();}
	} 
	 
	ServerSocketChannel serverChannel;
	public VocabServer(int port) throws IOException {
		serverChannel = ServerSocketChannel.open();
		selector = Selector.open();
		serverChannel.socket().bind (new InetSocketAddress(port));
		serverChannel.configureBlocking (false);
		serverChannel.register (selector, SelectionKey.OP_ACCEPT);		
		System.err.println("Vocab server initialized on port " + port);
	} 
	 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: register, bind, isOpen, configureBlocking
		} 
	} 
 
	@Override 
	protected final IoSession bind0(Set<SocketAddress> localAddresses) {
		if (serverSocketChannel.isOpen() && selector.isOpen()) {
			try { 
				serverSocketChannel.bind(localAddresses.iterator().next());
				if (serverSocketChannel.isOpen() && selector.isOpen()) {
					serverSocketChannel.configureBlocking(false);
					serverSocketChannel.register(selector,
							SelectionKey.OP_ACCEPT);
				} 
				// 
				init(); 
			} catch (IOException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: socket, validOps, isBlocking, isRegistered, provider
            // Android doesn't cache the timeout, so the getsockopt(2) fails and throws. 
        } 
    } 
 
    public void testChannelBasicStatus() { 
        ServerSocket gotSocket = this.serverChannel.socket();
        assertFalse(gotSocket.isClosed());
        assertTrue(this.serverChannel.isBlocking());
        assertFalse(this.serverChannel.isRegistered());
        assertEquals(SelectionKey.OP_ACCEPT, this.serverChannel.validOps());
        assertEquals(SelectorProvider.provider(), this.serverChannel.provider());
    } 
 
    // ------------------------------------------------------------------- 
    // Test for accept() 
    // ------------------------------------------------------------------- 
 
    /* 
     * Test method for 'java.nio.channels.ServerSocketChannel.accept()' 
     */ 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toString, socket, isOpen, isBlocking
		ch.configureBlocking(false);
	} 
 
	@Override 
	public String toString() {		
		return "InetServerSocket[" + ch.toString()  
			+ " open="+ch.isOpen()
			+ " blocking="+ch.isBlocking()
			+ " addr="+ch.socket().getLocalSocketAddress()
		    + "]";		 
	} 
 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: close
        cnxnFactory.shutdown();
 
        Field ssField = cnxnFactory.getClass().getDeclaredField("ss");
        ssField.setAccessible(true);
        ServerSocketChannel ss = (ServerSocketChannel) ssField.get(cnxnFactory);
        ss.close();
      } 
      close(); 
    } 
    catch (Exception e)
    { 
      e.printStackTrace();
    } 
  } 
 
  public void killPeerZkServer() 
  { 
    ZooKeeperServer zserver = _peer.getActiveServer();
 
    try 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
See Code Examples for Java 8 ServerSocketChannel Methods: