1.在会话中获得远程IP和端口
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
InetSocketAddress remoteAddress = (InetSocketAddress) session.getRemoteAddress();
System.out.println(remoteAddress.getAddress().getHostAddress()+" "+ remoteAddress.getPort());
}
2.在会话中获得本地IP和端口
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
InetSocketAddress localAddress = (InetSocketAddress) session.getLocalAddress();
System.out.println(localAddress.getAddress().getHostAddress()+" "+ localAddress.getPort());
}