📄 e175. writing to a socketchannel.txt
字号:
See also e173 Creating a Non-Blocking Socket.
// Create a direct buffer to get bytes from socket.
// Direct buffers should be long-lived and be reused as much as possible.
ByteBuffer buf = ByteBuffer.allocateDirect(1024);
try {
// Fill the buffer with the bytes to write;
// see e160 Putting Bytes into a ByteBuffer
buf.put((byte)0xFF);
// Prepare the buffer for reading by the socket
buf.flip();
// Write bytes
int numBytesWritten = socketChannel.write(buf);
} catch (IOException e) {
// Connection may have been closed
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -