Java: how to get the connection port from InetAddress?

I'm trying to use Apache Mina to build a socket server based on Java NiO I really need to know the port of the remote host, not just the IP address, and it seems that Mina only exposes the socketaddress object I can get the IP address from InetAddress, but I usually use socket Getport () to get the port number, but Mina seems to blur these low-level objects Is there another way? thank you!

Solution

Downconvert socketaddress to inetsocketaddress (not InetAddress, this is not a subclass); This exposes the port accessor

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>