You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Michael Grundvig <mi...@electrotank.com> on 2007/11/28 06:45:05 UTC

Port Oddities

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

RE: Port Oddities

Posted by Michael Grundvig <mi...@electrotank.com>.
Sorry for the delay in responding. I've been off-site for a few days.

The JVM is 1.6 32-bit version. We didn't test a non-MINA implementation.

Sadly, the client mis-reported results. getRemoteAddress() is failing as I described but apparently getLocalAddress() worked as expected. Still not sure why the remote address returns port 0 but we have a work around now and are good to go. Thanks for looking into this though!

Mike

-----Original Message-----
From: Angel.Figueroa [mailto:afigueroa@updatecom.com]
Sent: Friday, November 30, 2007 2:41 PM
To: dev@mina.apache.org
Subject: Re: Port Oddities


I am running a server application on linux intel 32 bit and linux s390x
(mainframe for linux), it work withou any problem. Also it return the
correct port number for each client connected to the server.

Regards,
Angel Figueroa


elihusmails wrote:
>
> did you try a simple non-MINA server and see what it returns?  If it is 0,
> then there must be something going on with Java on linux.
>
> BTW, what JDK are you using?
>
>
> On Nov 28, 2007 12:45 AM, Michael Grundvig <mi...@electrotank.com> wrote:
>
>> 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
>>
>
>
>
> --
> --------------------------------
> The adjuration to be "normal" seems shockingly repellent to me; I see
> neither hope nor comfort in sinking to that low level. I think it is
> ignorance that makes people think of abnormality only with horror and
> allows
> them to remain undismayed at the proximity of "normal" to average and
> mediocre. For surely anyone who achieves anything is, essentially,
> abnormal.
>     Dr. Karl Menninger
>
>

--
View this message in context: http://www.nabble.com/Port-Oddities-tf4886480s16868.html#a14093632
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Port Oddities

Posted by "Angel.Figueroa" <af...@updatecom.com>.
I am running a server application on linux intel 32 bit and linux s390x
(mainframe for linux), it work withou any problem. Also it return the
correct port number for each client connected to the server.

Regards,
Angel Figueroa


elihusmails wrote:
> 
> did you try a simple non-MINA server and see what it returns?  If it is 0,
> then there must be something going on with Java on linux.
> 
> BTW, what JDK are you using?
> 
> 
> On Nov 28, 2007 12:45 AM, Michael Grundvig <mi...@electrotank.com> wrote:
> 
>> 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
>>
> 
> 
> 
> -- 
> --------------------------------
> The adjuration to be "normal" seems shockingly repellent to me; I see
> neither hope nor comfort in sinking to that low level. I think it is
> ignorance that makes people think of abnormality only with horror and
> allows
> them to remain undismayed at the proximity of "normal" to average and
> mediocre. For surely anyone who achieves anything is, essentially,
> abnormal.
>     Dr. Karl Menninger
> 
> 

-- 
View this message in context: http://www.nabble.com/Port-Oddities-tf4886480s16868.html#a14093632
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: Port Oddities

Posted by Mark <el...@gmail.com>.
did you try a simple non-MINA server and see what it returns?  If it is 0,
then there must be something going on with Java on linux.

BTW, what JDK are you using?


On Nov 28, 2007 12:45 AM, Michael Grundvig <mi...@electrotank.com> wrote:

> 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
>



-- 
--------------------------------
The adjuration to be "normal" seems shockingly repellent to me; I see
neither hope nor comfort in sinking to that low level. I think it is
ignorance that makes people think of abnormality only with horror and allows
them to remain undismayed at the proximity of "normal" to average and
mediocre. For surely anyone who achieves anything is, essentially, abnormal.
    Dr. Karl Menninger