Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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? –  bummzack Feb 18 '12 at 12:08
add comment

5 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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...

share|improve this answer
1  
Where? Anyplace I find that is reputable is ~$20 a month. –  ClassicThunder 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 –  Amit Ofer 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. –  Lohoris 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 ;) –  Oskar Duveborn 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. –  Jonathan Dickinson Mar 19 '12 at 15:20
add comment

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.

share|improve this answer
    
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 –  Gustavo Maciel Mar 19 '12 at 14:33
    
I'd be more worried about jitter than overall latency in a general case, anyway. –  stephelton Mar 19 '12 at 15:37
    
I don't think latency and jitter are issues when it comes to turn-based games –  John McDonald Mar 19 '12 at 16:45
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Problem here is technical issues, not who should be a leader / host admin. –  Markus von Broady Oct 14 '12 at 10:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.