Being multiplayer, a game needs a server hosting. The question arises: where and how to host a server?
To answer the question, we have to know what our needs are.
- Lobby
- Persistence (ranking and matchmaking, last few matches, statistics, etc.)
- Medium speed / latency, no realtime is required (hooray for turn based games)
- >99% uptime
Since I am a wannabe indie developer, I am tight on budget. I could pay, however I rather wouldn't until this game has at least some success. But later I might have to rent a server (due to traffic), so ideally I would like to find some host which grants a free plan that can later be upgraded.
First, look at the options:
- Find a free webhost that lets you use PHP or some kind of scripting language.
- + Free
- - PHP!!!
- - Not really meant to be a game server
- Rent a server
- + Use your favourite language
- + Uptime is usually guaranteed
- - Money
- Cloud / Google App Engine (Did not consider Amazon or any other possibility)
- + No need to use PHP, you can use Python (or Java or Go)
- + Have free plans
- + Scalable
- - Very complexity, so features, wow, much buzzwords
There are other solutions, however this area is so new to me I wanted to cry from all the informations. These are the ones I still can remember. I chose Google app engine, since users praised it. I have downloaded Python 2.7, the Google App SDK, and created a simple web server locally, that replied "Hello world" to any incoming connection. Then I went to Unity, and added this little chunk of code:
void StartMultiplayer() {
string url = "localhost:8080";
WWW www = new WWW(url);
StartCoroutine(GetResponse(www));
}
IEnumerator GetResponse(WWW www) {
yield return www;
if (www.error == null) {
Debug.Log ("WWW Ok: " + www.text.ToString());
} else {
Debug.Log ("WWW error: " + www.error.ToString());
}
}
string url = "localhost:8080";
WWW www = new WWW(url);
StartCoroutine(GetResponse(www));
}
IEnumerator GetResponse(WWW www) {
yield return www;
if (www.error == null) {
Debug.Log ("WWW Ok: " + www.text.ToString());
} else {
Debug.Log ("WWW error: " + www.error.ToString());
}
}
I have added a "Multiplayer" button to the GUI, and tested it. It worked. (It took only 3 hours until I found this code snippet on the net and things finally started to work. I don't claim I understand what is happening, though.)
As I understood, I can store data in SQL table, so persistence is no problem. Lot of people on forums said that HTTP requests will be enough for turn based games (HTTP requests usually take about 1-2 seconds), so I'm optimistic about it.
No comments:
Post a Comment