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 で使用したオブジェクト タイプにメッセージをキャストします。