Question

I created a Battleship game in Java to work with Sockets and ServerSockets. The game works fine on LAN, but I would like to be able to play against someone on a completely different network. I understand port forwarding would be necessary, but would I have to forward the port on every client that is playing the game? Or would it only be necessary to forward the port on the router the server is using? Thanks.

Was it helpful?

Solution

Port forwarding is only required on the server. Any packets bound for the client will be auto-forwarded from the initial request thanks to the action on many NATs.

So, you only need to forward the port on the server. If using Socket and ServerSocket you need to forward TCP if your router gives you the choice. If using DatagramSockets, forward UDP at either of the endpoints.

(if you had to forward on clients, you most likely wouldn't have been reading this page without forwarding port 80)

OTHER TIPS

To elaborate on what @hexafraction is saying, here's what you can do:

Build a server that any client can connect to. Clients can generally connect to anything they want. Firewalls usually place restrictions on information that can flow in, but not flow out. So if the clients know the server to connect to, they can connect to it without modifying their firewall and then the server will coordinate transferring the data between the clients.

I did this and all I had to do was forward the port I was using in my router to my local I.P. address. If you don't know your local ip address run a command prompt (assuming your using windows ) and run ipconfig to figure it out. If your at home using a wireless router access it by browser to 192.168.1.1 Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top