# WinSock, PHP and Master Server

This topic is 3926 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 serverwrite("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 on other sites
Thanks a bunch guys, I'll have a look into http requests.