Пример #1
0
        private void OnPingRecieved(PingMessage message)
        {
            Logger.Debug("Recieved PING from {0}({1})", message.Address, message.Name);

            try
            {
                // Send the pong message, we do this as an extra hand shake since sometimes we're told
                // about a secondary address which only routes in one direction
                var client = new UdpMessageClient(Config.Instance.GetPort());
                client.Send(message.Address, Messages.BuildPongMessage().ToString());

                // Add the reply to our hosts file
                _hostFile.AddMapping(message.Name, message.Address);
            }
            catch (SocketException)
            {
                Logger.Warn("Address {0} is unroutable", message.Address);
            }
        }
Пример #2
0
        internal void OnBroadcastRecieved(BroadcastMessage message)
        {
            if (message.Name == Config.Instance.GetFriendlyHostname())
            {
                // Ignore broadcasts from ourselves
                return;
            }

            Logger.Debug("Recieved BROADCAST from {0}({1})", message.Address, message.Name);

            // Ping back to the broadcaster, so they know we're alive
            try
            {
                var client = new UdpMessageClient(Config.Instance.GetPort());
                client.Send(message.Address, Messages.BuildPingMessage().ToString());
            }
            catch (SocketException)
            {
                Logger.Warn("Address {0} is unroutable", message.Address);
            }
        }