forked from RevenantX/LiteNetLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNtpTest.cs
More file actions
38 lines (34 loc) · 1.03 KB
/
Copy pathNtpTest.cs
File metadata and controls
38 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Threading;
using LiteNetLib;
namespace LibSample
{
public class NtpTest : IExample
{
public void Run()
{
RequestNtpService("0.pool.ntp.org");
}
private void RequestNtpService(string ntpService)
{
Console.WriteLine($"Request time from \"{ntpService}\" service");
var ntpComplete = false;
EventBasedNetListener listener = new EventBasedNetListener();
listener.NtpResponseEvent += ntpPacket =>
{
if (ntpPacket != null)
Console.WriteLine("[MAIN] NTP time test offset: " + ntpPacket.CorrectionOffset);
else
Console.WriteLine("[MAIN] NTP time error");
ntpComplete = true;
};
NetManager nm = new NetManager(listener);
nm.Start();
nm.CreateNtpRequest(ntpService);
while (!ntpComplete)
{
Thread.Yield();
}
}
}
}