[英]Apache Mina: Get local port to which remote client connected
If I have a server listening on ports 80 and 8080 as configured below, how would I be able to identify which local port a client connected to when i get a message?如果我有一个如下配置的服务器监听端口 80 和 8080,当我收到消息时,我如何能够识别客户端连接到哪个本地端口?
acceptor = new NioSocketAcceptor();
acceptor.setHandler(new MyConnectionHandler());
Set<SocketAddress> addresses = new HashSet<SocketAddress>();
addresses.add(new InetSocketAddress(host, 80));
addresses.add(new InetSocketAddress(host, 8080));
acceptor.bind(addresses);
The handler's messageReceived I want to know which local port the client connected to, not the client's remote port.处理程序的messageReceived我想知道客户端连接到哪个本地端口,而不是客户端的远程端口。
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
log.info("Incomming: {}", session.getRemoteAddress().toString());
Which method should I use to access the port which should be 80 or 8080?我应该使用哪种方法访问应该是 80 或 8080 的端口? The log statement would print something like this:
日志语句将打印如下内容:
Incomming: /219.182.172.12:37921
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.