2

In Java, we can open a ServerSocket with new ServerSocket(port), and connect to it with new *Socket(server_adress",port)*;
But how to connect, if server is in a different network, while both networks are behind a NAT.

I know that there must be a solution. Skype and other applications already found it.

Any ideas ?

Regards, Andrew.

4
  • 1
    Are you actually having a problem if server and client are in different subnets or are you just assuming there's a problem? Show us some code you have tried and perhaps we can help you to resolve whatever problem you're having? Commented Jan 21, 2011 at 12:40
  • It doesn't matter wether the server and the client are on different subnets. What is the problem you are having? Commented Jan 21, 2011 at 12:40
  • 1
    this is less of a java question than a networking question really. you should give some more detail on the topology of your network (routers, NAT, IP addresses, ...) Commented Jan 21, 2011 at 12:42
  • There's 2 solutions, 1. Set up port forwarding in your router. 2. Do hole punching, like Skype does (expect to spend the better part of the year implementing this in a general fashion). Commented Jan 24, 2011 at 23:08

1 Answer 1

1

For a list of all the methods, some of which are used by Skype, see http://en.wikipedia.org/wiki/NAT_traversal

Once you've picked a method, use Google to search for a Java implementation of that method. (Or follow the links from that wiki page, e.g. http://jstun.javawi.de/ )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.