Thread: Using a web server for multiplayer hosting?

  1. #1
    Join Date
    Jan 2006

    Using a web server for multiplayer hosting?

    Hi, this isn't really urgent, it's just a thought I had. If I want to do multiplayer on my game, and I'm too cheap to afford a real server, can I use a web server with php modules to do the job? The server I'm using to host my site has a 300gb bandwidth limit per month, and all I need it for is keeping track of each individual server's IP address and ping (I'm planning to have users make their own servers, instead of having some dedicated ones).

    Is this idea totally crazy, or will it just be too slow, and if it will work, could you point me to some resources for scripting something like that in php, because I'm kinda rusty with php?

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    I'm not really sure what you're trying to do here...
    You want your web server (a simple PC) to send pings using the PHP module?

    It's not that crazy, BUT... if you don't own the server I don't think you will be able to send ICMP request from the server, it could be blocked!

    But if you can send and receive ICMP you will have to manage it right!
    You can't just let the ping run forever, it will kill your BW. You will have to do it smart, for example: a single ping every 5 min a packet with ZERO bytes as payload (data).

    As for the code itself, I don't know PHP, sorry... But I know a dear friend of mine, Google!
    Just find a php module or some ready code to send and receive the ICMP (ping).
    You can also call ping for OS command line, but I don't suggest you do that, since it could become a security hole in your code.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe - Developing free software for the community.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx
    You don't need ICMP. But this is absolutely do-able. Simply have your individual servers make a call to the php page, just like browser would, (perhaps sending a unique User-Agent for verification), along with their name, # players, or any other interesting info. (You can get the IP either by having your servers send it, or just read the $_SERVER variable.) Then, just store all the info that the server sent you somewhere (MySQL database would work fine.) along with the time you received the update. After this initial connection, you can have the server merely connect every ten minutes or so and say, "I'm still here, my data hasn't changed!" (to reduce bandwidth)

    Now, whenever someone wants the master server list, just query the database for any records within the last 10 min, and send it on back!
    (You could probably have either script also remove servers that have fallen offline.)

    Hopefully that's not the worst way of doing it, but it only requires a web server, PHP, and MySQL. Instead of the web server pinging all of it's hosts, it merely removes them if it doesn't hear from them in 10 mins. As for timing and bandwith issues, just keep your requests small, and perhaps limit them to 15 or 20 minutes depending on how many individual servers. At 5KB a ping, ping-ing every 5 minutes with 15 servers, it's only 670KB/month. Bandwidth should hopefully not be an issue.

    As for code, I know PHP, but you should work out the details yourself. This isn't just PHP - you'll need to store the data (perhaps using SQL), and send it to the web server. (HTTP & sockets, C? programming). I've though about doing this myself (and all I have is a webserver/PHP/MySQL) and that's what I've come up with. Hope it's not flawed in any way, and good luck!
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Cactus_Hugger, you're forgetting one small thing, he has a limitted amout of BW, and if he doesn't do it right he will burn it pretty fast!
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Server Architecture
    By coder8137 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-29-2008, 11:21 PM
  2. SWEBS Web Server
    By nickname_changed in forum A Brief History of
    Replies: 6
    Last Post: 09-22-2003, 02:46 AM
  3. Web Server in Router Network...
    By Aidman in forum Tech Board
    Replies: 15
    Last Post: 01-17-2003, 10:24 PM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. Web Hosting SQL Server
    By Unregistered in forum A Brief History of
    Replies: 0
    Last Post: 06-14-2002, 07:00 PM