Hi all; this might or might not be a MINA issue, but we see it in our MINA app 
and it's network related so I think I can get away with posting it here.

Inside of the SessionOpened event of our IOHandlerAdapter, we need to get the 
port number the client used to connect to the server. So if the server is 
listening on port 1234, we need the port integer in the code below to be 1234. 
This seems simple enough and both code snippets below work perfectly on Windows 
and OSX, but for some reason on CentOS both snippets give us a port of 0.

SocketAddress address = ioSession.getLocalAddress();
InetSocketAddress inetAddress = (InetSocketAddress) address;
int port = inetAddress.getPort();


SocketAddress address = ioSession.getServiceAddress();
InetSocketAddress inetAddress = (InetSocketAddress) address;
int port = inetAddress.getPort();

Why would both of these return 0 and only on Linux? Is there another way to 
accomplish this? As the server can be listening on many ip/ports at once, I 
can't seem to find a convenient work around. Any help would be greatly 
appreciated!

Thanks!

Mike

Reply via email to