Reputation: 9
I am implementing a Socket program in Java and realized that Socket and ServerSocket classes can only be used in my LocalNetwork.What i need to do,so that a remote PC(different router) can connect to my PC(server)?what API should i use?
Upvotes: 0
Views: 82
Reputation: 40395
"Socket and ServerSocket classes can only be used in my LocalNetwork."
Where did you get that from?
Anyway, the Socket and ServerSocket are not restricted to local network at all. This is not local:
Socket s = new Socket("www.java2s.com", 80);
However, if your client and server are on different networks, then you have to set up the proper routing (i.e. configure the router's DMZ, etc.).
Upvotes: 1
Reputation: 12538
There is no restriction, It can be used over the internet as well, Ideally what you want to do is to make sure your firewall permits you to connect to the port listened by the socket, you can create a port forwarding via your DMZ or NAT to filter and forward requests to the listening machine.
Upvotes: 1
Reputation: 500873
There is nothing about Socket
and ServerSocket
that limits them to the local network. There may be issues around firewalls and such, but the classes themselves won't place any additional constraints.
Upvotes: 5