Exemplo n.º 1
0
            protected override void Start(object arg)
            {
                var destination = ((ThreadArguments)arg).destination;
                var port = ((ThreadArguments)arg).port;
                var endpoint = new IPEndPoint(IPAddress.Any, 0);

                socket = new UdpClient(destination, port);
                socket.Client.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, true);
                Log.LogMessage("Connected to " + destination + " port: " + port);

                try
                {
                    socket.DontFragment = true;
                }
                catch { }

                ping = new PingT();

                pingtimer = new System.Timers.Timer();
                pingtimer.Interval = 200;
                pingtimer.AutoReset = true;
                pingtimer.Elapsed += new System.Timers.ElapsedEventHandler(OnPingTimerExpired);
                pingtimer.Enabled = true;

                Program.GUI.StartReplay += new StartReplayEventHandler(SetupStartTimer);

                while (true)
                {
                    var data = new byte[0];

                    try
                    {
                        data = socket.Receive(ref endpoint);
                    }
                    catch
                    {
                        continue;
                    }

                    if (data.Length == 12)
                    {
                        int command = BitConverter.ToInt32(data, 0);

                        if (command == PING)
                        {
                            ReplyToPing(null, data);
                            continue;
                        }

                        ping.Ping = GetPingFromData(data);
                        OnPingUpdate(ping.Ping);

                        if (command == START)
                        {
                            StartTimer((Program.StartAfterSeconds * 1000) - ((int)ping.Ping / 2));
                        }
                    }
                }
            }
Exemplo n.º 2
0
            protected override void Start(object arg)
            {
                var destination = ((ThreadArguments)arg).destination;
                var port        = ((ThreadArguments)arg).port;
                var endpoint    = new IPEndPoint(IPAddress.Any, 0);

                socket = new UdpClient(destination, port);
                socket.Client.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, true);
                Log.LogMessage("Connected to " + destination + " port: " + port);

                try
                {
                    socket.DontFragment = true;
                }
                catch { }

                ping = new PingT();

                pingtimer           = new System.Timers.Timer();
                pingtimer.Interval  = 200;
                pingtimer.AutoReset = true;
                pingtimer.Elapsed  += new System.Timers.ElapsedEventHandler(OnPingTimerExpired);
                pingtimer.Enabled   = true;

                Program.GUI.StartReplay += new StartReplayEventHandler(SetupStartTimer);

                while (true)
                {
                    var data = new byte[0];

                    try
                    {
                        data = socket.Receive(ref endpoint);
                    }
                    catch
                    {
                        continue;
                    }

                    if (data.Length == 12)
                    {
                        int command = BitConverter.ToInt32(data, 0);

                        if (command == PING)
                        {
                            ReplyToPing(null, data);
                            continue;
                        }

                        ping.Ping = GetPingFromData(data);
                        OnPingUpdate(ping.Ping);

                        if (command == START)
                        {
                            StartTimer((Program.StartAfterSeconds * 1000) - ((int)ping.Ping / 2));
                        }
                    }
                }
            }
Exemplo n.º 3
0
            private void UpdateClientPing(IPEndPoint endpoint, uint?ping)
            {
                var clientping = new PingT();

                if (clients.TryGetValue(endpoint, out clientping))
                {
                    if (ping != null)
                    {
                        clientping.Ping = (uint)ping;
                    }
                }
                else
                {
                    Log.LogMessage("New client " + endpoint);
                    clients.Add(endpoint, clientping);
                }
            }
Exemplo n.º 4
0
            protected override void Start(object arg)
            {
                var port = (int)arg;
                var endpoint = new IPEndPoint(IPAddress.Any, port);

                try
                {
                    socket = new UdpClient(endpoint);
                    socket.Client.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, true);
                    socket.DontFragment = true;
                }
                catch
                {
                    Log.LogMessage("Failed to create server on: " + endpoint);
                    return;
                }

                Log.LogMessage("Server created on: " + endpoint);

                ping = new PingT();
                clients = new Dictionary<IPEndPoint, PingT>();

                pingtimer = new System.Timers.Timer();
                pingtimer.Interval = 200;
                pingtimer.AutoReset = true;
                pingtimer.Elapsed += new System.Timers.ElapsedEventHandler(OnPingTimerExpired);
                pingtimer.Enabled = true;

                Program.GUI.StartReplay += new StartReplayEventHandler(SetupStartTimer);

                while (true)
                {
                    var clientendpoint = new IPEndPoint(IPAddress.Any, 0);
                    var data = new byte[0];

                    try
                    {
                        data = socket.Receive(ref clientendpoint);
                    }
                    catch
                    {
                        continue;
                    }

                    if (data.Length == 12)
                    {
                        int command = BitConverter.ToInt32(data, 0);
                        if (command == PING)
                        {
                            ReplyToPing(clientendpoint, data);
                            UpdateClientPing(clientendpoint, null); // add the new client
                            continue;
                        }

                        var receivedping = GetPingFromData(data);
                        ping.Ping = receivedping; // update global ping average
                        OnPingUpdate(ping.Ping);
                        UpdateClientPing(clientendpoint, receivedping); // update per-client average

                        if (command == START)
                        {
                            StartTimer((Program.StartAfterSeconds * 1000) - ((int)clients[clientendpoint].Ping / 2));
                        }
                    }
                }
            }
Exemplo n.º 5
0
 private void UpdateClientPing(IPEndPoint endpoint, uint? ping)
 {
     var clientping = new PingT();
     if (clients.TryGetValue(endpoint, out clientping))
     {
         if (ping != null)
             clientping.Ping = (uint)ping;
     }
     else
     {
         Log.LogMessage("New client " + endpoint );
         clients.Add(endpoint, clientping);
     }
 }
Exemplo n.º 6
0
            override protected void Start(object arg)
            {
                var port     = (int)arg;
                var endpoint = new IPEndPoint(IPAddress.Any, port);

                try
                {
                    socket = new UdpClient(endpoint);
                    socket.Client.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, true);
                    socket.DontFragment = true;
                }
                catch
                {
                    Log.LogMessage("Failed to create server on: " + endpoint);
                    return;
                }

                Log.LogMessage("Server created on: " + endpoint);

                ping    = new PingT();
                clients = new Dictionary <IPEndPoint, PingT>();

                pingtimer           = new System.Timers.Timer();
                pingtimer.Interval  = 200;
                pingtimer.AutoReset = true;
                pingtimer.Elapsed  += new System.Timers.ElapsedEventHandler(OnPingTimerExpired);
                pingtimer.Enabled   = true;

                Program.GUI.StartReplay += new StartReplayEventHandler(SetupStartTimer);

                while (true)
                {
                    var clientendpoint = new IPEndPoint(IPAddress.Any, 0);
                    var data           = new byte[0];

                    try
                    {
                        data = socket.Receive(ref clientendpoint);
                    }
                    catch
                    {
                        continue;
                    }

                    if (data.Length == 12)
                    {
                        int command = BitConverter.ToInt32(data, 0);
                        if (command == PING)
                        {
                            ReplyToPing(clientendpoint, data);
                            UpdateClientPing(clientendpoint, null); // add the new client
                            continue;
                        }

                        var receivedping = GetPingFromData(data);
                        ping.Ping = receivedping;                       // update global ping average
                        OnPingUpdate(ping.Ping);
                        UpdateClientPing(clientendpoint, receivedping); // update per-client average

                        if (command == START)
                        {
                            StartTimer((Program.StartAfterSeconds * 1000) - ((int)clients[clientendpoint].Ping / 2));
                        }
                    }
                }
            }