A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Running multiple online games(PHP SOCKETS)

  1. #1
    Programmer
    Join Date
    Aug 2007
    Posts
    173

    Running multiple online games(PHP SOCKETS)

    Hello

    I have recently been building a flash game inspired by minecraft, (in 2D)

    currently still just building the engine of this, i have started taking into consideration the possible online aspects of the game.

    i am completely capable of building the nessesary things needed for 2 players to play with each other.

    However i have no idea to how i can make 100s of 2 player games on the same server?

    would i use the same script to run on a dynamic port?
    e.g ( some form of lobby that uses a unique port number for every user game created? ) is this practical?


    cheers
    Freelance: AS2, AS3, PHP, MySQL, JavaScript
    Skype: hunty93

  2. #2
    Funkalicious TOdorus's Avatar
    Join Date
    Nov 2006
    Location
    Nijmegen, Netherlands
    Posts
    697
    Hi Hunty, I won't be able to help you much, but I'm also considering a multiplayer game using a Flash client and a Java backend. We may be able to help each other out in the design aspects of our projects.

    Since you're building a game that is limited to two players, I'm guessing you're just using your backend as a proxy, while one of the two clients acts as a master and the other as a slave?

    The way I was thinking of making the initial setup for a game, is to first let the client request a game. The server will then send a game object containing an ID a hashcode and possibly some game data. The id and hashcode are stored on the server in a database. I don't really know how php works, but in order for my java implementation to be threadsafe I want my controller part to be as stateless as possible, so I'll be using a database alongside it.

    Now that the clients and backend all have the game token, the backend can use this to verify which game a request applies to. This way you have one single endpoint which can handle an unlimited number of games (from a pure software perspective). Using the hashcode which is generated server-side, the user cannot interfere with other games, as it would know how the hashcode is generated.

    I'm also considering red5 which should handle this differently, by using a remote SharedObject, which should also use some kind of token or socket to keep games seperate. Also this solves the problem of scalability, since polling in short intervals to a webserver won't allow for that many concurrent users. I don't know if there are php based solutions that use a remote SharedObject though.

  3. #3
    Programmer
    Join Date
    Aug 2007
    Posts
    173
    hey TOdorus,

    thank you for your reply,

    so from what i can make of your idea, you plan to run all of your rooms over a single port?

    i also had the idea to use some form of unique ID via database thus making load up game data cleaner to store and access. However, im not too sure how i would go about using the id code with sockets. and also, are you planing on keeping the database entries forever? or do you have an idea to automatically remove them.

    im pretty happy with how i have got my Flash side infrastructured to deal with incoming data.

    with all this, i think maybe a lobby script that loads all the active databases into rooms. and sends back this data to flash with the hash keys to connect with.

    the user will then connect to the set default port , with the hash key and the socket script will deal with the rest.

    im just trying to think of a method that splits up all the binded clients to there set place ;/
    Freelance: AS2, AS3, PHP, MySQL, JavaScript
    Skype: hunty93

  4. #4
    Senior Member Wancieho's Avatar
    Join Date
    May 2002
    Posts
    370
    You may already know some of this but just highlighting from my experience:

    I created a chat room in flash a while back using a socket server and AS2. Not sure how much better AS3 handles sockets but you will probably need to look into running on a web server with shell access and a static IP. If you have this covered then most of your problems are already sorted, the rest are just architecture decisions. The hosting company I use wont allow a socket server on a shared server so thats also something you need to check. You could also run the web server from a local network and use DYNDNS to handle "static" IPs.

    As far as creating "grouped" connections I would leave it all up to the socket server-side script to handle the linking based on requests from flash.

    You can easily clear DB entries when the socket close event fires.

    I havent tried using ports but it sounds like dodgy territory. Router port forwarding may become and issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center