Apache MINA networking - How to get data from org.apache.mina.core.service.IoHandlerAdapter messageRecieved(IoSession, Object)
public void messageReceived(IoSession session, Object message) throws Exception
{
// do something
}
Can开发者_StackOverflow anyone tell me how to get data from the Object?
It's really quite simple, just cast the message into an IoBuffer and pull out the bytes.
// 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));
Cast message to the object type you used in the client's session.write.
精彩评论