public void messageReceived(IoSession session, Object message) throws Exception
{
// do something
}
谁能告诉我如何从对象中获取数据?
public void messageReceived(IoSession session, Object message) throws Exception
{
// do something
}
谁能告诉我如何从对象中获取数据?
这真的很简单,只需将消息转换为 IoBuffer 并提取字节即可。
// cast message to io buffer
IoBuffer data = (IoBuffer) message;
// create a byte array to hold the bytes
byte[] buf = new byte[data.limit()];
// pull the bytes out
data.get(buf);
// look at the message as a string
System.out.println("Message: " + new String(buf));
将消息转换为您在客户端 session.write 中使用的对象类型。