Code example for SocketChannel

Methods: registerconnectconfigureBlocking

	private boolean tryToConnect(InetSocketAddress remote) {
		// The WebSocket constructor expects a SocketChannel that is 
		// non-blocking, and has a Selector attached to it. 
		try { 
			client =;
			selector =;
			this.conn = new WebSocket(client,
					new LinkedBlockingQueue<ByteBuffer>(), this);
			// At first, we're only interested in the 'CONNECT' keys. 
			client.register(selector, SelectionKey.OP_CONNECT);
		} catch (IOException ex) {
			onIOError(conn, ex);
			return false; 
Contextual code suggestions in your IDE  Get Codota for Java