# Is it possible to use 3G internet for a TCP/IP game server?

I'm working on a turned based multiplayer android game with a friend. I started working on the game server and client using socket programming. I found a few tutorials on how to implement a basic chat on android and I started extending that example to suit my needs. Basically the game is really simple and the communication only include sending a few string from the client to the server every turn and sending the calculated scores back to all the clients after each turn. the idea is that one of the players creates the game and thus initialize the server, and each player connects to this client using ip. I tried this solution and it seems to work great when all the players are using the same wifi connection or by using router port forwarding. The problem is when trying to use 3G internet for the server, I guess the problem is that 3G ip address isn't global and you can't use port forwarding there, correct me if I'm wrong here.

Is there a way to overcome this issue? or the only solution is to limit my game to wifi only or think of a different solution than the standard socket programming solution? I.E web server etc.

what do you think would be the best approach here?

Thanks.

• Are you talking about a peer-to-peer approach (where a client becomes the "server")? Or why would you use 3G internet for the server? Feb 18 '12 at 12:08

Due to the fact that your game is turn-based you can get quite creative with your solution - you can still run the server on one of the phones but you don't need to rely (directly) on a direct IP connection.

In your situation what I would do is implement the XMPP protocol and send game state via that protocol - XMPP is particularly well suited to this because it is not only restricted to human-to-human messages (you would use IQ stanzas to transfer the commands) - and servers should blindly transmit IQ stanzas that they don't understand. The advantage here is that GTalk uses XMPP so you can obviously take advantage of Google's infrastructure (or indeed any public XMPP server like Jabber.org).

Finally you could also try and initially negotiate a Jingle session. If your NAT is traversable you would thus get a P2P connection, and if it is not you could simply use the XMPP connection that you have open. I doubt you would actually need to do this though, because of the fact that your game is turn-based.

As far as I know, usually 3G connections are NATted, so they can't be used as a server.

Why you would want to do it in the first place is beyond me. Get a real server. You can rent a VPS for like 5$/month or even less... • Where? Anyplace I find that is reputable is ~$20 a month. Feb 18 '12 at 14:55
• the reason for this is that I want one of the players' phone to act as a server. you open a game and people join you, then you have both a server and a client on your device, and you get to be "the game host". each game is for 2-4 players Feb 18 '12 at 18:53
• @AmitOfer: since likely they are NATted, you can't do it unless you use an external server and do some voodoo. Since you have to use an external server anyway, actually use that as a server while you are at it.
– o0'.
Feb 18 '12 at 23:21
• The spare 3G I keep are not NATted (public dynamic IP) but depending on the sub-carrier there is an active outbound portfilter anyway - negating inbound connections. However, one subcarrier says they filter it all but, they don't - I use them as the passive standby internet-connection for my hobby email- and web-servers ;) Feb 19 '12 at 11:36
• STUNT or TURN might be able to get around certain NATs - I have personally hosted AAA servers (which usually have these features) through a NATted 3G connection. Therefore I must downvote because it definitely is possibly; and there is some likelihood that one of the players has a traversable NAT. Mar 19 '12 at 15:20

Aside from technical issues, the latency is going to be terrible. If you Google the major carriers you'll see reports of 200ms to 900ms latency - most definitely not suitable for a game server.

• For a turn based game, as the op mentioned, this is relevant, lol. You won't be doing nothing before you turn, so the gameplay maay still ok even with 4s latency Mar 19 '12 at 14:33
• I'd be more worried about jitter than overall latency in a general case, anyway. Mar 19 '12 at 15:37
• I don't think latency and jitter are issues when it comes to turn-based games Mar 19 '12 at 16:45

The only way to host over 3g would probably be to setup the 3G device to use a VPN, but it would be easier to just setup a Rackspace Cloud VPS.

Instead of having some one host it, just have the server make the first person in the room be the leader, and have the ability to pass leadership of they leave the game. Plus maybe use a password system for private games, but all servers show up in a public list, and have a lock icon next top the password servers. If someone starts a server they should be able to change the name and setting as leader.

• Problem here is technical issues, not who should be a leader / host admin. Oct 14 '12 at 10:16