• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Help, remote port = 0.

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic