MartyIX
MartyIX

Reputation: 28648

How to set the same time on both computers connected over network in .NET?

I'm trying to be fair play in my network game and I would like to mark as winner the player who won first and it depends on time but DateTime.Now is local time and both computers may have set different times on their machines.

Is there something that .NET provides for this case?

Thanks!

Upvotes: 0

Views: 104

Answers (3)

TheCloudlessSky
TheCloudlessSky

Reputation: 18353

If there is no server involved why don't you get the time difference of machines and then add/subtract accordingly for the "other computer"'s time?

Upvotes: 1

Incognito
Incognito

Reputation: 16577

If you need to check who was first to finish some task or something I would suggest you to use some kind of timer. For example you can use StopWatch. However if the machine time is essential for the application the only reliable time in your case is server time, so you can work only with it.

Upvotes: 2

µBio
µBio

Reputation: 10748

Normally you would base this on server time, otherwise it can(will) be spoofed by cheaters.

Upvotes: 2

Related Questions