Reputation: 377
My question: How do I establish a connection from a client on one network to a server on another network in Java?
Background: I created a simple client and server that communicate fine using localhost, or on two different computers using the same network. I connect using the inet address (e.g. inet 10.xx.xx.xx) and a port number (e.g. 55123).
I realize that my client cannot find my server because they are on different networks, i.e. the ip address and port do not provide enough info for the client to find the server.
sock = new Socket(10.xx.xx.xx, 55123);
What am I missing for my client on the other network to find my server?
Thank you very much for your help!
James
Upvotes: 1
Views: 3174
Reputation: 718826
Your problem is not Java specific. This is really about how IPv4 / IPv6 networking / addressing works.
The 10.0.0.0/24
network range is reserved for private networks; see Wikipedia's "Private Network" article.
If the server has a 10.xx.xx.xx
address, AND your client is on a different network, then it is simply not possible for your client to connect directly to the server. Your client's network simply cannot route packets to the server's network.
(Indeed, there are millions of networks around the world that use 10.xx.xx.xx
addresses. Your server's IP address is not unique ... except in the context of the private network it is attached to. So which of the many possible servers with IP of (say) 10.42.42.42
servers should the client's packets be routed to?)
Possible solutions:
Upvotes: 2