Java 8 SocketChannel - 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 SocketChannel class.

This code example shows how to use the following methods: socket, configureBlocking
    public SocketConnection(SocketChannel socket, MessageSerializer<T> serializer) {
        this.socket = socket;
        try { 
            // NOTE: we use non-blocking IO as there is no reliable way when using blocking IO to shutdown reads while 
            // keeping writes active. For example, Socket.shutdownInput() does not work on Windows. 
            socket.configureBlocking(false);
            outstr = new SocketOutputStream(socket);
            instr = new SocketInputStream(socket);
        } catch (IOException e) {
            throw UncheckedException.throwAsUncheckedException(e);
        } 
        InetSocketAddress localSocketAddress = (InetSocketAddress) socket.socket().getLocalSocketAddress();
        localAddress = new SocketInetAddress(localSocketAddress.getAddress(), localSocketAddress.getPort());
        InetSocketAddress remoteSocketAddress = (InetSocketAddress) socket.socket().getRemoteSocketAddress();
        remoteAddress = new SocketInetAddress(remoteSocketAddress.getAddress(), remoteSocketAddress.getPort());
        objectReader = serializer.newReader(instr, localAddress, remoteAddress);
        objectWriter = serializer.newWriter(outstr);
    } 
 
    @Override 
Full Snippet Info
8
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: connect, finishConnect, isConnected, isConnectionPending, close
        this.channel1.close();
        assertFalse(this.channel1.isOpen());
    } 
 
    public void testIsConnected() throws Exception {
        assertFalse(this.channel1.isConnected());// not connected
        this.channel1.configureBlocking(false);
        assertFalse(this.channel1.connect(localAddr1));
        assertFalse(this.channel1.isConnected());
        assertTrue(this.channel1.isConnectionPending());
        assertTrue(tryFinish());
        assertTrue(this.channel1.isConnected());
        this.channel1.close();
        assertFalse(this.channel1.isConnected());
    } 
 
    public void testIsConnectionPending() throws Exception {
        // ensure 
        ensureServerClosed(); 
        this.channel1.configureBlocking(false);

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: configureBlocking
	} 
 
	public void connect() { 
		try { 
			channel = SocketChannel.open(new InetSocketAddress(host, port));
			channel.configureBlocking(false);
		} catch (IOException e) { e.printStackTrace(); }
		socket = new AsynchronousSocket(channel);
		IOLoop.INSTANCE.addHandler(channel, socket, SelectionKey.OP_READ, ByteBuffer.allocate(1024));
	} 
	 
	public void get(String value, AsyncResult<String> cb) {
		socket.write("GET deft\r\n", new WriteCallback(cb));
	} 
	 
	private class WriteCallback implements AsyncCallback { 
 
		private final AsyncResult<String> cb;
		 
		public WriteCallback(AsyncResult<String> cb) { 
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: connect, socket, configureBlocking, AbstractSelectableChannel.register
        return false; 
    } 
 
    private void configureSocket() throws IOException {
        if (socketChannel!=null) {
            socketChannel.configureBlocking(false);
            socketChannel.socket().setSendBufferSize(getTxBufSize());
            socketChannel.socket().setReceiveBufferSize(getRxBufSize());
            socketChannel.socket().setSoTimeout((int)getTimeout());
            socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerOn()?getSoLingerTime():0);
            socketChannel.socket().setTcpNoDelay(getTcpNoDelay());
            socketChannel.socket().setKeepAlive(getSoKeepAlive());
            socketChannel.socket().setReuseAddress(getSoReuseAddress());
            socketChannel.socket().setOOBInline(getOoBInline());
            socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
            socketChannel.socket().setTrafficClass(getSoTrafficClass());
        } else if (dataChannel!=null) {
            dataChannel.configureBlocking(false);
            dataChannel.socket().setSendBufferSize(getUdpTxBufSize());
            dataChannel.socket().setReceiveBufferSize(getUdpRxBufSize());

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
	} 
	 
	@Override 
	public String toString() {
		 
		return "InetClientSocket[" + ch.toString()  
			+ " open="+ch.isOpen()
			+ " addr="+ch.socket().getLocalSocketAddress()
			+ " remote="+ch.socket().getRemoteSocketAddress()
		    + "]";		 
	} 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 SocketChannel Questions & Answers:

See Code Examples for Java 8 SocketChannel Methods: