Firewall or Routers preventing connection.

I am using Java1.4 and making a game using tcp/ip play. Both the client and server side will only work if the computer has no firewall or router preventing it (NAT Firewall for instance). I seen many games where you could at leist JOIN a game but not host, if u had these problems. If I could fix that workaround, it would mean a majority of players would be able to play, just they need 1 of the 2 being able to host. Anyone knows how to enable this?

I know the solution is that u open ports or forward ports but if any user is not able to do so, will it then automatically fail or can that user still be able to join?

Oh, by the way.

On the server side I use
ServerSocket listenSocket = new ServerSocket(Global.GAME_PORT);
Socket clientSocket = listenSocket.accept();

On the client side i use
Socket serverSock= new Socket(this.connectToIP, Global.GAME_PORT);

Any client can connect to:

  • any server not behind a router
  • any server behind a router with the appropriate ports forwarded (NAT)

So the player that hosts the game has to have a server-setup like described above.
All others will find it.

Oh, and be sure to bind the ServerSocket to the public IP (or the local IP that is ‘connected’ to the router).

You might find this thread useful.

The UPnP library is a great piece of work, but most routers now come with it disabled for security reasons. So rather than open a port, the user has to enable UPnP before the game (as a server at least) will work. So it’s questionable whether this is an improvement.

I had a go at this (networking, not UPnP) last year and found that there’s a number of other things worth thinking about…

The client-server model with the server not behind a router generally works well. If the server is hosted on the same machine as a webpage hosting the applet or webstart app, then you may not even need to sign the applet/app (unless you want full screen, or native libraries, and for the second you might get away solely with a set of signed libraries). The client server model also allows you to keep all the major game logic on the server, which is easier to program & allows easy storage of player game state.

However client-server routes all the data through the server. Thus if you have 4 clients, each using 25kbps of bandwidth, then the server has to handle 100kbps. If you had 10 players, this increases to 250kbps. Overall, if the game is turn based, then the bandwidth per client is low, and you can use a client server model with no problem. However, for a real time game, the data transmitted can quickly get out of hand, requiring a huge bandwidth at the server. If this was paid for hosting, it would get expensive. If it was a several megabit home broadband connection & the server was only up for a limited time, it’ll probably be Ok. Just estimate the bandwidth per player & calculate how many players can share the server.

Alternatively you could consider peer-peer networking. Each client has to talk to every other client, so the client bandwidth increases significantly. There is now a limit on the number of simultaneous players based on the player with the slowest connection. It is also more difficult to program & you need to sign the app/applet so it can communicate to any address on the internet. To make it work through routers, you need to use a technique called UDP Punch through. (Use google to find articles). This needs a small server to make it work - The server tracks current players & allows new players to join. Worth considering if you want to leave you server up all the time, but don’t want to max out your bandwidth.

WHetehr ro not you can make an outbound TCPIP conectionre ally depends on teh firewall and configuration.

On MOST home firewalls by default you can, however many coproations block almost all outgoing ports on their foirewalls.

Simialrly on MOST home systems you can send a UDP packet out. The firewall wil lautomagically map an external port for return messages and re-write that as well as the IP on the packet so IF the server uses the port and IP specified for return messages then they will get through.

However older firewalls may not and again corporate firewalls often block this.

Ehm? The routers map the ports, not the firewalls.

Maybe you’re talking about routers with embedded firewalls?

Depends on the system.

On linux the firewall, IPChains, does port mapping.

shrug

In m sot common hosuehold situations yes the firewall is part of the router.