apache mina 发送和接收 字节数组 byte[]
}
/**
? * 当一个客户端关闭时
? */
@Override
public void sessionClosed(IoSession session) throws Exception {
? System.out.println(session.getRemoteAddress() + "is Disconnection");
}
@Override
public void messageReceived(IoSession session, Object message)
?? throws Exception {
?????? IoBuffer ioBuffer = (IoBuffer)message;?
?????? byte[] b = new byte[ioBuffer.limit()];?
?????? ioBuffer.get(b);
???
? String msg=new String(b);
? System.out.println("收到客户端发来的消息为" + "? " + msg);
?
? //将测试消息会送给客户端
? //session.write(str + count);
}
}
运行结果:
服务器在端口:8800已经启动
incoming client: /127.0.0.1:1353
收到客户端发来的消息长度为? 13
收到客户端发来的消息为? aaaaaaaaaaaaa
?