473,769 Members | 6,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer issue

Hey guys

Here is what i want to do. I have made a multiplayer game that needs to when
more than one player is ready start a countdown that the clients can see,
so players can still join in this time frame and then after the time elapses
the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be serialised.

My second problem is i think this may be flawed, if it takes longer for data
to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same timer??

Thanks
Apr 22 '06 #1
4 1696
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestry online.com> wrote in message
news:ua******** ******@TK2MSFTN GP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the game
| logic, deciding who wins, who is next to play etc. For all the players to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that is
| sent to the clients.
|
| The idea being the clients receive that object and they will then continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|
Apr 22 '06 #2
Hi William,

Ok so step by step your saying:

1) instantiate timer on the server
2) send to each player currently ready (once i have more than 1) a time span
object
3) now start the servers timer
4) clients on receiving the timespan object start their timers
5) anyone new joins in this time they are sent the timespan as it stands on
the server at this stage (so maybe 20seconds left), they then start their
timers from there
6) when server hits 0 send the start game to all clients
Thats sounds like a good method, there is one more problem though. my game
can have 3 or 4 games upto 100 going at once. So each game needs its own
timer tracked independantly.

At first thought a TimerManager class springs to mind where i can have every
game running tracked via a unique id number and on a player joining a game i
check which game he/she has joined and return the time details from the
timemanager class for that game.

My only problem is from a design point of view this could get messy. It
would mean i would have to when i instantiate my games do something liek
this:

GameManager.Cre ateGame("Game1" , 1);
TimerManager.Cr eate(1);

where 1 is the unique id.

Ideally i would want the timermanager done inside the gamemanager class but
that class is serialised and sent to the client on connecting so they can
see all the available games. As a result i cant put the timer manager in
there as it would need to be serialisable and i cant serialise a timer.

Anyway round that? I dont want future coders to forget to create a
timermanager for each game, plus they would have to always stay in sync.

Look forward to your views.

"William Stacey [MVP]" <wi************ @gmail.com> wrote in message
news:O5******** ******@TK2MSFTN GP03.phx.gbl...
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't
get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestry online.com> wrote in message
news:ua******** ******@TK2MSFTN GP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can
see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the
game
| logic, deciding who wins, who is next to play etc. For all the players
to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that
is
| sent to the clients.
|
| The idea being the clients receive that object and they will then
continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|

Apr 22 '06 #3
sb
Synchronization is probably the most common concern in all MPOGs. One
approach is to measure & track the time it takes for a packet of data to
complete a round trip (server -> client -> server) for each connected
client. This value can be used by the server to determine when to send
packets to each client as well as when to completely disconnect them...ie
they are responding too slowly.

For example:
Client A has a round-trip time (RTT) of 100 ms or ~50ms one-way
Client B has a round-trip time (RTT) of 200 ms or ~100ms one-way
Client C has a round-trip time (RTT) of 500 ms or ~250ms one-way

Now let's say I have some data that each client needs to see at the same
time...such as a player shooting a bullet. Knowing the information above I
can do the following and be fairly confident that everyone will be in synch:
Send C the data packet...wait 150ms and send client B the data, wait
50ms more and send client A the data.
Of course, this method requires that you frequenty check the latency of
every client because connections vary over time....but this does get you
down to milliseconds in terms of accuracy. Depending on what your game does
and how much timing matters in it, you can take the above scenario and add
many more levels of complexity to measuring the latency more accurately.
Alas, this is just one way to do it that isn't too complicated.

-sb
"Daniel" <Da*****@vestry online.com> wrote in message
news:ua******** ******@TK2MSFTN GP03.phx.gbl...
Hey guys

Here is what i want to do. I have made a multiplayer game that needs to
when more than one player is ready start a countdown that the clients can
see, so players can still join in this time frame and then after the time
elapses the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be
serialised.

My second problem is i think this may be flawed, if it takes longer for
data to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same
timer??

Thanks

Apr 22 '06 #4
You can still put the timer logic in the Game class. Just mark the timer
var and [nonserialized] or what ever the attribute is as I can't remember.
If xml, private vars will not be serialized anyway, only public properties
with get and set.
1) Create the game.
2) First client starts the timer (for example)
3) Future clients get a timespan between now and future time.
4) If client get into the game before timer trigger, then good, otherwise
return failure to client.

It probably makes sense to keep the timer logic close to the client connect
logic, where ever that is. If in the game class, great place to put it.
hth

--
William Stacey [MVP]

"Daniel" <Da*****@vestry online.com> wrote in message
news:uF******** ******@TK2MSFTN GP05.phx.gbl...
| Hi William,
|
| Ok so step by step your saying:
|
| 1) instantiate timer on the server
| 2) send to each player currently ready (once i have more than 1) a time
span
| object
| 3) now start the servers timer
| 4) clients on receiving the timespan object start their timers
| 5) anyone new joins in this time they are sent the timespan as it stands
on
| the server at this stage (so maybe 20seconds left), they then start their
| timers from there
| 6) when server hits 0 send the start game to all clients
|
|
| Thats sounds like a good method, there is one more problem though. my game
| can have 3 or 4 games upto 100 going at once. So each game needs its own
| timer tracked independantly.
|
| At first thought a TimerManager class springs to mind where i can have
every
| game running tracked via a unique id number and on a player joining a game
i
| check which game he/she has joined and return the time details from the
| timemanager class for that game.
|
| My only problem is from a design point of view this could get messy. It
| would mean i would have to when i instantiate my games do something liek
| this:
|
| GameManager.Cre ateGame("Game1" , 1);
| TimerManager.Cr eate(1);
|
| where 1 is the unique id.
|
| Ideally i would want the timermanager done inside the gamemanager class
but
| that class is serialised and sent to the client on connecting so they can
| see all the available games. As a result i cant put the timer manager in
| there as it would need to be serialisable and i cant serialise a timer.
|
| Anyway round that? I dont want future coders to forget to create a
| timermanager for each game, plus they would have to always stay in sync.
|
| Look forward to your views.
|
| "William Stacey [MVP]" <wi************ @gmail.com> wrote in message
| news:O5******** ******@TK2MSFTN GP03.phx.gbl...
| > Send a TimeSpan (say 30 seconds) to all clients. It is a duration in
the
| > future so it will be relative to any timezone or system time. You can't
| > get
| > it *exact, but a second or two should not be an issue. If a client
comes
| > in late, then that is just the way the ball bounces. Start your timer
on
| > the server after the last client message is sent so that should give
| > everyone at least 30 seconds (for example) to connect - the first
clients
| > may wait a tiny bit longer, but that should be ok.
| >
| > --
| > William Stacey [MVP]
| >
| > "Daniel" <Da*****@vestry online.com> wrote in message
| > news:ua******** ******@TK2MSFTN GP03.phx.gbl...
| > | Hey guys
| > |
| > | Here is what i want to do. I have made a multiplayer game that needs
to
| > when
| > | more than one player is ready start a countdown that the clients can
| > see,
| > | so players can still join in this time frame and then after the time
| > elapses
| > | the game starts.
| > |
| > | I am trying to do it lie this, my server controls all handling of the
| > game
| > | logic, deciding who wins, who is next to play etc. For all the players
| > to
| > | have their timers showing the same times i have created the timer on
the
| > | server and this time is then serialised as part of the game object
that
| > is
| > | sent to the clients.
| > |
| > | The idea being the clients receive that object and they will then
| > continue
| > | to be running the timer their end with it having started at the server
| > | theoretically making the timers go in sync.
| > |
| > | My problem is first of all that System.Timers objects cannot be
| > serialised.
| > |
| > | My second problem is i think this may be flawed, if it takes longer
for
| > data
| > | to reach one client his timer will start slightly late etc.
| > |
| > | Anyone have any ideas how i can do this so all players see the same
| > timer??
| > |
| > | Thanks
| > |
| > |
| >
| >
|
|
Apr 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
7498
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
3
5608
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan dueTime) is always set to 6 days, 23 hours, 59 minutes, .. Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day .. Any suggestion
2
1725
by: Benjamin | last post by:
Hi, I am having a problem enabling a timer in my class. I have attached some sample pseudo code (see "Sample code illustrating issue") so you can see what I am talking about. Whats the issue? ================ I am unable to pause the timer when a timed event is thrown due to my event handling having a private scope. If I make the scope public all works as expected.
5
5092
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue control. The service will "sleep" for 'n' seconds using the timer control and whenever the timer_elapsed event occurs, I use the performance counter object to determine availability of few resources. Based on the availability of resources, I use the...
8
2737
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a thread to access the database and then displays a modal dialog which allows the user to cancel the task, if it is taking longer than they want, and shows them a display of how long the query has been running so far.
7
6077
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
10
4301
by: igor | last post by:
I have recently discovered that the system.Timers.Timer from.Net Framework v1.1 is not reliable when used on Windows 2003 server. When incorporated into a Windows Service, the timer_elapsed event will stop executing after 30 to 40 days. After learning this, I found the same issue had been documented in the the System.Threading.Timer class as well. This limits my options for having a timer based windows service using the .net framework....
3
2475
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I am trying to use the timer to make a login form show after a specified interval. However, if the interval is set to a value greater than 5000 nanosecond, then it does not respond. What could be the issue here? Thanks. private void frmMain_Load(object sender, EventArgs e) { this.timer = new Timer();
8
3373
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location on a network for files and then copies these files to another location (on the network) AND then updates a record in the database. The file copying is performed before the database update because the file system is not transactional. The code...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.