File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Help, remote port = 0. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Help, remote port = 0." Watch "Help, remote port = 0." New topic
Author

Help, remote port = 0.

Gal Rubinstein
Greenhorn

Joined: Jan 13, 2008
Posts: 13
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

Joined: Mar 07, 2007
Posts: 1282

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

Joined: Jan 13, 2008
Posts: 13
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

Joined: Jan 03, 2006
Posts: 490
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.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Gal Rubinstein
Greenhorn

Joined: Jan 13, 2008
Posts: 13
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
Sheriff

Joined: Sep 28, 2004
Posts: 19068
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Gal Rubinstein
Greenhorn

Joined: Jan 13, 2008
Posts: 13
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help, remote port = 0.