The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: Synchronizing Realtime Multiplayer games

  1. #1

    Synchronizing Realtime Multiplayer games

    After having made a turn-based Multiplayer implementation of Minesweeper Flags at my site, I want to go into real-time Multiplayer development.
    The turn-based Minesweeper Flags game can be found here: http://www.zomis.net/games/flags

    The easiest real-time multiplayer thing that came to my mind was to have two squares travel around the playfield. I've made it working, but it isn't synchronized. When player1's x-position is 110 for Player1, Player1's x-position might be 104 for Player2. Only 6 pixels difference, but in realtime Multiplayer it must be perfect. All players move 10 times per second - a local timer controls this movement.

    I'm working in Flash (ActionScript 3.0) and using a PHP script as the server. I've implemented it so that any command that a player executes (change speed or change direction) is first sent to the server, then being sent back to all clients. And then all clients execute the action for the correct player.

    So what techniques should I use to make my games synchronized? I don't want to send too much data back and forth all the time, there has to be a better way, right?

  2. #2
    If you're doing this over HTTP, your clients have to poll a webserver, which is inefficient. This could work fine for a pulse-based multi-player game where the pulses occur as often as every few seconds, but for an action-based game at 10 times a second, I don't think it will work very well (just ten players online at a time would generate 100 hits per second).

    Another option would be to use sockets, which I think is the way to go if your game's action occurs at a rate of multiple times per second:
    http://www.gotoandplay.it/_articles/...4b9b5e75e8e4be

  3. #3
    Here's some advice. The client only sends input. The server is 100% authoritative. When the client presses a key down send a packet to the server and on the server for that player make a bool true. Do the same for key up and set it to false. The server updates at a given tick rate. Real time can be anywhere from 2 to 10 times per second normally. When the server updates it looks at the boolean values for the input. Things like moveUp, moveLeft and so on. During this time it performs the changes to the characters velocity and the server-side collision detection. At the end of the update tick it iterates the players and compiles packets for them containing the changed data (delta packets) and sends them to the players. Position and velocity are sent. The velocity is used for interpolation on the client between updates. You can formulate the equations for interpolation given latency.

    You may be wondering how to serialize your data. Here read this

    Definitely look at sockets if you aren't already. Also PHP will start to break down after around 100 simultaneous connections and such. It's not really designed to run in a loop. C# has the .NET asynchronous sockets and C++ has Boost.Asio also asynchronous. Both are scalable, but can be difficult to use without proper knowledge of threading.

    For more about synchronization look into EPIC. It's something a mod wrote up over at gamedev.

    Also as you'll notice the binary format for data is preferred. XML and strings are to be avoided for real-time applications.

    I'm not sure what your experience level is so that should keep you busy.

  4. #4
    I am already using sockets, sorry for not clarifying this earlier. I am fully aware that HTTP requests would not work well for real-time multiplayer games.

    I don't know much C/C++/C# so I will try to stick with PHP. I hope that it won't break apart, I doubt I will have 100 online players at the same time anyways. I also know nothing about threading.

    I've learned a few things though after reading your posts and after checking around on gamedev.net. I'll try with a clock-synchronization kind of thing, not a real one but maybe close. Just a little number which tells how many times my timer has executed it's function. This number will be sent along with the action messages. For example, "COMM 3 68 1036" says that player 3 issue command 68 on timeframe 1036, currently only "COMM 3 68" is being sent. I might change this to binary messages using Socket class instead of XMLSocket.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012