Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help, remote port = 0.

 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm trying to open an application using a ServerSocket inside a thread like so:



and I get that the remote port is 0.

even if I try opening the server socket with just the port number I get the same affect... like so:



what is the problem?

Thank you,
Gal
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gal,

I don't really understand the problem. Where do you see that any remot port is "0"? Are you talking about the server side or the client side? If you're opening a socket we're only on the server side. What else does this application do?

Marco
 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco Ehrentreich wrote:Hi Gal,

I don't really understand the problem. Where do you see that any remot port is "0"? Are you talking about the server side or the client side? If you're opening a socket we're only on the server side. What else does this application do?

Marco


I would try to explain :

the main problem is that I cannot to connect to this server, the one I mention, from any computer other then localhost. I'm sure its not firewall it's disabled and the router has been set.
so, when I say 'remote' a mean "open for anther computer on the network".. hope this helps.

when I do a System.out.println of the ServerSocket I see:


so 'port=0', I'm guessing that the is the port to machines outside localhost.

what do I do?

hope this makes it clearer.

Thanks
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you think that you are binding to port 0?

The ServerSocket constructor:

ServerSocket(int port, int backlog, InetAddress bindAddr)

The integer value 0 is the backlog, which is the connection queue. It has nothing to do with ports.

the port is the local port for the process running the server and is the remote port for the client.

In the toString call, the port is always zero, which is fairly meaningless for our purposes. You never use port 0, since it is either an invalid port or some OS's use it for specifying dynamic ports. The 4444 is the local port and is what clients specify when connecting.

When you use the constructor that accepts an IP address and call getLocalHost(), not only is it redundant since the other constructors use local host by default, it could be the problem why you can't connect.

Is the client on the same machine? If so, barring any weird firewall issues and making sure the client connects to 4444, you should be able to connect.

If the client is on a different machine, then try and figure out why would can't connect to another machines local host.

IP 0.0.0.0 is the wildcard, so you should be able to connect. Again it depends on firewalls, and whether or not you put the correct ip address and port number in the client Socket connection.
 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeap, it works..

I just had to use the server's machine 'name' and not it's local ip to connect to the server.... probably the DNS person will be able to explain this.

also I added the 'server' vm argument: java -server -jar xxx.jar

Thanks a lot,
Gal
 
Henry Wong
author
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also I added the 'server' vm argument: java -server -jar xxx.jar


The "-server" option has nothing to do with networking. This option specifes that the JVM should use the "server" JIT compiler -- which is optimized better for longer running programs.

Henry
 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
also I added the 'server' vm argument: java -server -jar xxx.jar


The "-server" option has nothing to do with networking. This option specifes that the JVM should use the "server" JIT compiler -- which is optimized better for longer running programs.

Henry


Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic