Apache Mina:获取远程客户端连接的本地端口
如果我有一个服务器按照下面的配置侦听端口 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);
处理程序的 messageReceived 我想知道客户端连接到哪个本地端口,而不是客户端的远程端口。
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
log.info("Incomming: {}", session.getRemoteAddress().toString());
我应该使用哪种方法来访问端口,应该是80还是8080?日志语句将打印如下内容:
Incomming: /219.182.172.12:37921
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?
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.
@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? The log statement would print something like this:
Incomming: /219.182.172.12:37921
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
session.getLocalAddress()< /代码>
session.getLocalAddress()