更新时间:2023-02-09 14:06:28
这里可能是一些示例代码解决问题:
Here might be some sample code to fix the problem:
while(iterator.hasNext())
{
SelectionKey key = iterator.next();
channel.receive(buffer); // The buffer is a ByteBuffer.
buffer.flip();
byte[] bytes = new byte[buffer.limit()]; // copy buffer contents to an array
buffer.get(bytes);
// thread will convert byte array to String
new Thread(new ThreadToPrintTheMessage(bytes)).start();
buffer.clear();
iterator.remove();
}