Networking architecture for a turn based game

Monkey Forums/Monkey Programming/Networking architecture for a turn based game

Rushino(Posted 2012) [#1]
Hello,

I was planning to make a turn based game with PubNub. I am a bit lost now.. i wanted to use a WebAPI to coordinate the requests since i wanted my game to be based on HTML5. However, i feel like doing that over HTTP using GET will be a bottleneck because this protocol will have to establish a new connection each time i make a request and this gateway will be receiving lots of incoming traffic (no outcoming because pubnub is the actual one that sending back data to clients). So i wonder if this gonna be actually a real problem..

I though i would go HTML 5 since it support Http GET right now rather easily but if HTTP is a bottleneck this probably isnt the way to go. Since HTML 5 doesn't support Async TCP Sockets i can't communicate through a stdcpp console. So there no much options left.. i could go Android or Glfw since it can do tcp but only Android seem to support PubNub right now (API ported to monkey that support pubnub) the funny thing is that i need the server to support pubnub AND the client. So what should i do ?

Thanks!


Xaron(Posted 2012) [#2]
Pubnub is great for turn based (or non time critical) games when you don't have to send that many messages. Pubnub itselfs runs on all platforms, I still did not have the time to port it for all.

The plain old HTTP protocol still has this problem that you don't have real client/server connections because it's a connectionless protocol, the server simply can't push messages to the client without tricks.

This has changed with the introduction of Websockets for HTML5. So I think that's the way to go. HTML5 is able to make non blocking calls.

If you want to have it easy, use Pubnub. I think the implementation in MNet is already non blocking, so fire and forget. Sure, you have to do some polling in your update sync loop to see if there's something new to get, but this isn't a biggy.

Main drawback of Pubnub is the price I guess. It's very affordable if you don't have that many messages, so for turn based games it's ok I think.


Rushino(Posted 2012) [#3]
Yeah.. but doing my research it seem PubNub is not sufficient alone if you want to handle security that a guy from the support that told me that. He said the prefered method is a client, a server and then pubnub. The server is the only one who get the publish key.. the reason is easy its because the server can handle the requests and validate them otherwise this become an hacker paradise. Furthermore, you probably want to handle a user base or something so you need a database the server is perfect for this task of storing and retrieving stuff. The server is infact your game logic.

Anyway i asked someone who seem to know well how HTTP work and for turn based game its probably not a problem because you send messages not that often.

About WebSockets.. i might have a look to this to know how that work. Might be a better solution.


Rushino(Posted 2012) [#4]
Alright, did very fast research and ive come up with something in C#..

There a WebSocket library for C# (called Alchemy) which you could use to make a server : http://olivinelabs.com/Alchemy-Websockets/

I just tried it and it work very good! Only minimal code are needed to connect to it so i think i will start making it a module for Monkey i think this could be pretty useful.

What do you think ?


Why0Why(Posted 2012) [#5]
Webservices are pretty easy to write in .NET. Anyone that is proficient enought to write a multiplayer game in Monkey shouldn't have an issue. You could uses the webservice for secure calls to a local database server for username and login and any other secure information. Then you could use PubNub for the game data. PubNub also supports SSL if you need it. I looked into it for something I was looking at that required security.


Rushino(Posted 2012) [#6]
Well i think ive got all i need to make this game now. The alchemy server is really answome! I am currently adding features to it. Hopefully i will have something working with websockets pretty soon.


Armitage1982(Posted 2012) [#7]
Did you check RakNet? It's pretty powerful and even got a NAT Punchtrough plugin allowing most users to connect easily while behind a router.

It's Free for Hobbyist.


Rone(Posted 2012) [#8]
What about Photon Cloud/Server? I'm using PhotonCloud for my rts game. Its pretty fast and very easy to use...


Rushino(Posted 2012) [#9]
Ive looked at your solution rone and Photon Server seem interesting i will have a look to it.