Sign in to follow this  
m4tthead

WinSock, PHP and Master Server

Recommended Posts

Hey, I'm totally new to network programming, but I've been doing some research in the last few days and have decided to use winsock for the multiplayer fps I'm making. One of the things I'm having trouble figuring out, is how I would get a master server set up. Since I have a slow upload speed, and very limited bandwidth, running a master server on a pc at my house isn't really an option. So I was thinking of getting some decent paid hosting, and running a server on that using php. I don't know much php, but I know you could store server information in a mysql database, and have a few different .php files for registering your server, removing your server, getting a list of active servers (which could also trim servers which haven't sent an update in X seconds). I was just wondering if this idea is plausible, and if so, how I would go about accessing the .php files, and sending data to them from my server application, and if this is possible using winSock? Thanks heaps :) -Matt

Share this post


Link to post
Share on other sites
PHP files are generators/scripts that produce some output, typically a HTML document. So you access the result of what you want as a .html we page.

What you now need to figure out is how to allow clients to register themselves. Most likely, this would be done with one of the HTTP queries.

The PHP scripts for both of those are more or less trivial.
- When a client requests registration, you look up their IP, put that into DB

- When client queries this master server, it simply downloads a html page and parses that to obtain the IPs of other clients. The script that generates this page can also use that time to check for expired IPs.

Winsock on the other hand is just implementation of TCP/IP stack. What you send over it is irrelevant. There's probably a few implementations of HTTP you could use to access the pages.

I don't know, this is a somewhat simple solution, but not particularly robust. You'd need some way to distinguish clients behind NATs, prevent spiders from registering themself as a client, you'd also have no reliable means of checking or polling clients. And tying all of this into MySQL back-end is quite a heavy solution, if you get a moderate number of clients. You'd probably also rely on each client to periodically ping the server to let it know they are still alive.

Share this post


Link to post
Share on other sites
The idea is completely plausible. You can use winsock, but it does mean writing the HTTP request yourself. You'd need something like:
//open connection to web server

write("GET /registerserver.php?ip=1.2.3.4&port=1000 HTTP/1.1\r\nHost: myhost.com\r\n\r\n", ...);


Then in the PHP you have something like
<?php

$ip = $_GET["ip"];
$port = $_GET["port"];

//add it to the database

?>


This is of course, completely unsecure, but it's a reasonable start.

Regards
elFarto

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this