Best code examples for Java 8 SocketChannel class (java.nio.channels.SocketChannel)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SocketChannel class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 SocketChannel examples from Open Source projects
This code example shows how to use the following methods: socket, configureBlocking
53:	socket.configureBlocking(false); 
54:	outstr = new SocketOutputStream(socket); 
55:	instr = new SocketInputStream(socket); 
-
59:	InetSocketAddress localSocketAddress = (InetSocketAddress) socket.socket().getLocalSocketAddress(); 
-
61:	InetSocketAddress remoteSocketAddress = (InetSocketAddress) socket.socket().getRemoteSocketAddress(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: connect, finishConnect, isConnected, isConnectionPending, close
138:	assertFalse(this.channel1.isConnected());// not connected 
139:	this.channel1.configureBlocking(false); 
140:	assertFalse(this.channel1.connect(localAddr1)); 
141:	assertFalse(this.channel1.isConnected()); 
142:	assertTrue(this.channel1.isConnectionPending()); 
-
144:	assertTrue(this.channel1.isConnected()); 
145:	this.channel1.close(); 
146:	assertFalse(this.channel1.isConnected()); 
-
219:	assertTrue(this.channel1.isConnected()); 
220:	assertFalse(this.channel1.isConnectionPending()); 
221:	assertTrue(this.channel1.isOpen()); 
-
229:	assertTrue(this.channel1.isOpen()); 
-
231:	connected = this.channel1.finishConnect(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: configureBlocking
33:	channel.configureBlocking(false); 
-
35:	socket = new AsynchronousSocket(channel); 
36:	IOLoop.INSTANCE.addHandler(channel, socket, SelectionKey.OP_READ, ByteBuffer.allocate(1024)); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: connect, socket, configureBlocking, AbstractSelectableChannel.register
136:	socketChannel.configureBlocking(false); 
137:	socketChannel.socket().setSendBufferSize(getTxBufSize()); 
138:	socketChannel.socket().setReceiveBufferSize(getRxBufSize()); 
139:	socketChannel.socket().setSoTimeout((int)getTimeout()); 
140:	socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerOn()?getSoLingerTime():0); 
141:	socketChannel.socket().setTcpNoDelay(getTcpNoDelay()); 
142:	socketChannel.socket().setKeepAlive(getSoKeepAlive()); 
143:	socketChannel.socket().setReuseAddress(getSoReuseAddress()); 
144:	socketChannel.socket().setOOBInline(getOoBInline()); 
145:	socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime()); 
146:	socketChannel.socket().setTrafficClass(getSoTrafficClass()); 
-
248:	if ( socketChannel.connect(addr) ) { 
-
250:	socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this); 
-
252:	socketChannel.register(getSelector(), SelectionKey.OP_CONNECT, this); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: toString, socket, isOpen
147:	return "InetClientSocket[" + ch.toString() 
148:	+ " open="+ch.isOpen() 
149:	+ " addr="+ch.socket().getLocalSocketAddress() 
150:	+ " remote="+ch.socket().getRemoteSocketAddress() 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close
93:	if (sc != null) sc.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: write
96:	if (ioLoop.hasKeepAliveTimeout(channel)) { 
-
106:	channel.write(mbb); 
-
109:	Closeables.closeQuietly(channel); 
-
124:	bytesWritten = channel.write(toSend); 
-
127:	Closeables.closeQuietly(channel); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: isConnected, isOpen
127:	return socketChannel_.isOpen() && socketChannel_.isConnected(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: isOpen
74:	return socketChannel.isOpen(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: socket, close, configureBlocking
162:	logger.info("New connection from " + channel.socket().getInetAddress().getHostAddress() 
-
165:	channel.close(); 
-
169:	channel.configureBlocking(false); 
170:	Socket socket = channel.socket(); 
-
184:	channel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: close
117:	connection.cancelReadSelect( target_channel ); 
118:	connection.cancelWriteSelect( target_channel ); 
-
120:	target_channel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: close
231:	sc.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: register, connect, finishConnect, isConnected
53:	socketChannel.connect(remote); 
-
62:	socketChannel.finishConnect(); 
63:	channelKey = socketChannel.register(selector, SelectionKey.OP_READ); 
-
67:	if (!socketChannel.isConnected()) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: close
77:	_channel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: write, close, isOpen
302:	if( socketChannel.isOpen() ) 
303:	socketChannel.write( wrap( emptybuffer ) );// FIXME what if not all bytes can be written 
304:	socketChannel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: write
360:	int wrote=channel.write(wbuf); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: socket
32:	return String.format("%s to %s", socket.socket().getLocalSocketAddress(), socket.socket().getRemoteSocketAddress()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: register, write, configureBlocking
62:	client.configureBlocking(false); 
63:	client.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE); 
-
67:	client.write(dst); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: read, socket, write, close
80:	Socket socket = socketChannel.socket(); 
-
86:	socketChannel.read(buffer); 
-
93:	socketChannel.write(encode(sb.toString())); 
-
105:	fileChannel.transferTo(0, fileChannel.size(), socketChannel); 
-
112:	socketChannel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: read, socket
44:	int bytesRead = socketChannel.read(buffer); 
-
47:	throw new IOException("Reached an EOL or something bizzare occured. Reading from: " + socketChannel.socket().getInetAddress() + " BufferSizeRemaining: " + buffer.remaining()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: read, close
98:	int num = sc.read(in_bb); 
-
102:	sc.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: close
282:	if (socketChannel != null) socketChannel.close(); 
-
292:	Util.close(socketInputStream, socketOutputStream, socketChannel); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: socket, close
165:	sc.socket().setSoLinger(true, 0); // await TIME_WAIT status 
166:	sc.socket().shutdownOutput(); 
167:	sc.close(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: isConnected, socket, configureBlocking
73:	if (!socketChannel.isConnected()) throw new IOException("Socket must already be connected"); 
-
82:	socketChannel.configureBlocking(false); 
-
85:	Socket socket = socketChannel.socket(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: read, socket
44:	 
-
47:	int size = CassandraUtilities.byteArrayToInt(buffer_.array()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: read, socket
44:	 
-
47:	StartState nextState = stream_.getSocketState(TcpReader.TcpReaderState.DONE); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: close
77:	_channel.close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: isConnected, close
35:	return _socketChannel != null && _socketChannel.isConnected(); 
-
62:	_socketChannel.close(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: close
81:	m_socket.close(); 
Full Snippet Info
6
CodeRank
Related Java 8 SocketChannel Questions & Answers:
See Code Examples for Java 8 SocketChannel Methods: