dcsimg
A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Multiplayer

  1. #1
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325

    Question Multiplayer

    Hey,

    I want to add multiplayer to a game - think ***** hotel.

    Requirements:
    • 10 people max (probably 2 or 3 at a time)
    • Smooth(ish) walking animations
    • a simple chat box


    Idea 1
    I was wondering, could i call a PHP script every 1/2 second or so to send the position of the character and any chat text and get, in return, the position and chat of other people/characters?
    Would it be fast enough?
    If not, how quickly could i update via this method do you think?

    Idea 2
    Using SmartFoxServer (http://www.smartfoxserver.com/) [because it's free for <20 people simultaneously], could i run this on my computer? (through a 4mb internet connection).
    Would that work? be fast enough?

    Idea 3
    Well not an idea but where do you buy servers that let you install your own software? and how much are they?


    Thanks for any help,

    Chris

    EDIT: When i say "smoothish walking animations"... - could i have it so the whole thing only updates every second or few seconds, so in the local game (controlling YOUR character) it moves smoothly. But when it updates 2 seconds later, it sends your CURRENT position, not the path you've taken.
    At the other end, on the other users's screens, a simple bit of path finding makes YOUR character move to your current position.
    How's that?
    Last edited by chriso20; 07-08-2008 at 11:00 PM.

  2. #2
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,796
    That's kind of how Club Penguin works...

  3. #3
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    You mean SmartFoxServer? - which it uses, so yes you're right.. any idea of creating something similar without a socket server?

  4. #4
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    If you will only have less than 10 people on at once, then you can probably get away with polling a PHP script. Just poll the script every few seconds and you'll probably be fine. Keep in mind that polling can put a significant load on a server if you get too many users. How many users is too many will depend on your system.

    If you think you'll want to expand the system in the future, your best bet is to either purchase a socket server or write your own. There are a ton of tutorials on how to do this in Java.

    Well not an idea but where do you buy servers that let you install your own software? and how much are they?
    You'll probably be interested in what they call "virtual private servers". Basically you get the control of a full server without the cost. Check out http://www.zone.net/.

  5. #5
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    Awesome, thanks for the reply flashisland!

    I'll be sure to post it up when i get it going

    I keep playing with the order of 'page calls' (for want of a better term). Basically, CLIENT>SERVER data ("i've just moved my character from here to here" or chat messages) can happen as and when they.. happen.
    Whereas checking for other peoples updates is blind - "have they moved?.. no.. have they moved?.. no.. etc..".

    I'm guessing this is what socket servers do? Basically talk to the client, instead of the client 'asking' if there's anything new (i really have v.little knowledge of them)

    I could cut down on bandwidth/etc.. by just having a yes/no binary response and doing it more often, "anything? 0 anything? 0 anything? 1 - what is it? x20,y45,msg-Hello%20I've moved!"..

    Can anyone sort of back me up as for this being the best/cheap(£+bandwidth)/simple way of making a multiplayer game?

  6. #6
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    PHP polling is certainly the cheapest way of making one, and you seem to have the right idea about it. It will probably just about take that kind of load. It's very fiddly, though, and will put a lot of stress on your bandwidth (only time I've ever gone over my site's bandwidth limit was when I had an automatically updating PHP-polled chatroom being hosted).

    And you're also correct that a socket server pushes data without having to receive a request beforehand. This is the nature of a socket connection; a consistent connection is made between client and server, whereas with polling, every message requires the connection to be re-established and then ended.

    One oversight I see here... your "anything? 1 - what is it?" has a wasted step. A better way to do it would just be "anything? x20,y45,msg-Hello%20I've moved!"

    Something to note about polling... it has A LOT more overhead than a socket connection, because even though you may only be sending a small "anything?" message, that gets header text clipped onto it, making it unavoidably large.

    As for calling the script every 1/2 second... depends how much latency there is on the connection. You might find that it's a good idea to have each client update at different intervals, based on their latency.
    http://www.birchlabs.co.uk/
    You know you want to.

  7. #7
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    what would happen if you sent another request before the last one had returned? (obviously this is easily checked for, i'm just curious)

    & thank you for the reply

  8. #8
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    Quote Originally Posted by chriso20
    what would happen if you sent another request before the last one had returned?
    It is possible for your second request to return before your first request. You could prevent this by time-stamping every returning response. If you have received responses from requests that have a larger time stamp than an incoming response, then you know that the response is old and can be discarded. If you're worried about losing chat messages, just discard the movement data and display the old chat text.

  9. #9
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    awesome, thanks for clearing that up.

    Another quick question - is there any way of monitoring how much bandwidth i use?
    Like for example, i host 3 other websites for clients, as well as much personal website - i don't want my little multiplayer experiment to go over the bandwidth limit and bring their sites down.

    Cheers again,
    Chris

  10. #10
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    Quote Originally Posted by chriso20
    Another quick question - is there any way of monitoring how much bandwidth i use?
    You'd need to talk to your web host about this issue. Most web hosts give you a way of monitoring your bandwidth within a control panel or on an account information page.

  11. #11
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,356
    For obvious reasons I'm going to recomend ElectroServer (which is also free for what you are doing) but you would do fine with either it or SmartFox
    You'll probably be interested in what they call "virtual private servers". Basically you get the control of a full server without the cost.
    This is a sticky one - Virtual Private Servers seem perfect BUT many of them are quite slow as you are still sharing the hardware with other people. We'd had very limited success when using them for multiuser sites. Technically they work fine if you get root access but the hosting companies usually don't want you to run a service on the box if they can avoid it.

    With that said, we host about twenty dedicated servers here and have had good luck:
    http://www.theplanet.com/dedicated-servers/

    As for polling, I put together a blog post that talks about it in detail here:
    http://mikegrundvig.blogspot.com/200...-to-avoid.html

    Good luck and have fun!

  12. #12
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    Virtual Private Servers seem perfect BUT many of them are quite slow as you are still sharing the hardware with other people.
    I completely agree...I tried out one VPS provider and they were slower than shared hosting. There are a few really great VPS providers out there (like the one I mentioned above) that will allow you to do pretty much anything. If they won't let you run a service on your account, then they really shouldn't be calling it VPS.

    The problem with dedicated servers is that a lot of people simply don't need them. For an application with a maximum of ten people at a time, don't waste your money.

  13. #13
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    superb replies, thank you!

    I now really don't think a VPS is the way to go, i don't need anything major.

    Cheers again, i now know where to go from here!

    Chris

  14. #14
    Senior Member lapo73's Avatar
    Join Date
    Jun 2003
    Location
    italy
    Posts
    395
    Yep, I agree VPS may not be the best choice.
    It really depends a lot on how much physical memory you have available and if you have root access.
    Usually very cheap VPS hosting plans have resource limitations and maybe they don't allow full root access, but you can also find very good plans that guarantee enough resources and no other limitations.
    Unfortunately I can't provide actual names of good ones or bad ones as I don't have a direct experience but I've heard both good stories and not-so-good ones from different customers and users.

    Talking about the specific case of SmartFoxServer we do have a hosting partner which offers dedicated SFS hosting at reasonable prices. I am not publishing the details here, but if you visit our website you can learn all the details. (check signature)

    Hope it helps

    Lapo
    www.gotoandplay.it
    Flash game developers community
    www.smartfoxserver.com
    Multiplayer Flash Server

  15. #15
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    709
    I never experimented multiplayer games, but I don't understand why we need a FLASH multiplayer server like SmartFox or ElectroServer. A socket is a socket wether you manage it in Flash or Java ?
    So why can't we use any open source multiplayer/chat server ?

  16. #16
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    So why can't we use any open source multiplayer/chat server ?
    Of course you can use any socket server software you want. Flash doesn't care/know that it's a "flash" socket server. The nice thing about SmartFox and ElectroServer is that they provide pre-written classes to interact with Flash, so it's a bit of a time saver. If you're willing to do that work yourself, then any socket server software will do.

  17. #17
    Pixel Artéést chriso20's Avatar
    Join Date
    Apr 2003
    Location
    Notts, UK
    Posts
    325
    Just interested now but..

    Is there any way of finding out how much bandwidth i've used in a single request?

    So i send a request to a PHP page, it checks if the other person has moved, if so, they send x:10,y50 back. But that's cost additional information in overheads/wrappers...

    Is there a way of finding the RAW code that was sent, not just the information required?

    Thanks

  18. #18
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,796
    I doubt you can install a server on a VPS, unless the server runs just via PHP, or CGI or something like that. Most (all?) VPS hosts won't allow compiled apps to be installed and executed. "Virtual Private Server" is just that... "Virtual" which means that installing custom software is a security and resource risk that impacts everyone else hosted on the same box.

    You may have to resort to dedicated.

  19. #19
    Senior Member flashisland's Avatar
    Join Date
    Aug 2003
    Posts
    241
    Most (all?) VPS hosts won't allow compiled apps to be installed and executed.
    I've seen VPS policies both ways. Some allow apps, others don't. Lots of VPS providers are a complete waste of money (practically the same as shared hosting) but there are also some that are excellent. You just need to shop around.

  20. #20
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,356
    Is there any way of finding out how much bandwidth i've used in a single request?
    and
    Is there a way of finding the RAW code that was sent, not just the information required?
    Yup. I use WireShark (http://www.wireshark.org/) personally. It will grab the entire byte stream and give it to you. The number of bytes of the messages + headers and all that is how big it was. Likewise it will show you the contents of the packets as well.

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