Networking in GM

M

mr_wordcraft

Guest
Hey, guys, sorry if I'm posting this on the wrong thread but I've been wanting to ask this questions for a while and the forums we locked so imma get it out of the way.

I'm building a 4 player multiplayer game on android(or at least that's what I WANT) but I have no idea how to set a server for people to play the game, right now I'm having no problems running multiple clients connected to the server but they are all inside my computer so there are no different IPs getting into the game. My question is, though, can it be done? Do I have to set a server for everyone who's going to play to connect to, or can I connect the clients directly?(I read that that can be done but I'd like to know all my alternatives before I fully commit to this plan) If I have to make a server for people to connect, how would I go about doing that?(Instead of using my own computer to keep the server) How do I have multiple servers so other people can play and have multiple groups of 4 players playing individual game matches?

I'm sorry if the questions are stupid/obvious but I'm new to this whole networking thing and I'm not the type of person to be above asking stupid questions if it means that I learn something new.
 
A

Aleksandar Gavrilovic

Guest
I don't know how to go about establishing a peer-to-peer connection (like Tor?) without a central server. That would be great, of course... I'm watching the thread for that answer too xD

But! The second option is real easy. I made an android chess game in that fashion. Here's how you do it (there are other ways of course). You can buy a domain and some server space real cheap (cca 1$/month) or if you already have a website then you don't even need to buy anything. Just make all the data go through the server and write some serverside code in a language you're familiar with. It should just basically send data to your game and the game should pick it up using the HTTP Async Event. The functions for sending data are http_get and http_post. You need to send packets and then the server distributes them to everybody "in game".
 
M

mr_wordcraft

Guest
Awesome! I already have a website set up so I'm going to read up more on those functions and see what I come up with, thanks!
 
A

Aleksandar Gavrilovic

Guest
This is the easiest way to go, I think:
After choosing a name for yourself, the player enters the "lobby room" with 2 options: create a game or join a game from the list of created games
When you "Create a game" you send your name to the server (for example with http_get to some serverside script you made)
The serverside script then creates a (txt) file with that name.
The list of created games is refreshed (let's say every 5s with an alarm event) and calls for another serverside script.
The second script just lists all (txt) files that are "available" (do this with flags or whatever).
These files obviously contain and transmit all the game info. When enough people join, the files are "locked" (for example with a flag inside the file or something).
Then the players enter the game and periodically (depending on the game genre really) send/receive variables with another (third) serverside script.
This second script updates/sends the (txt) file. Here you have to be careful with race conditions and mutex locks and so on...
Of course, this could all be one script with various arguments, or even more scripts or whatever, depending on your architecture and design choices and the game, really...
 
Top