1
public void messageReceived(IoSession session, Object message) throws Exception 
{
    // do something
}

オブジェクトからデータを取得する方法を教えてもらえますか?

4

2 に答える 2

2

メッセージを 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));
于 2011-11-15T21:20:22.680 に答える
0

クライアントの session.write で使用したオブジェクト タイプにメッセージをキャストします。

于 2011-04-26T10:06:19.480 に答える