Пример #1
0
        private async void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            string remoteAddress = args.RemoteAddress.CanonicalName;

            // Reject messages from this computer
            if (remoteAddress == information.LocalAddress)
            {
                return;
            }

            using (DataReader reader = args.GetDataReader())
            {
                byte[] data = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(data);

                EndpointInformation message = EndpointInformation.Deserialize(data);

                if (message != null)
                {
                    // Did message originate from a client?
                    if (message.Type == EndpointType.Client)
                    {
                        message = new EndpointInformation()
                        {
                            Address = information.LocalAddress,
                            Type    = EndpointType.Server
                        };

                        await SendMessage(message);
                    }
                }
            }
        }
Пример #2
0
        protected void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            string remoteAddress = args.RemoteAddress.CanonicalName;

            // Reject messages from this computer
            if (remoteAddress == information.LocalAddress)
            {
                return;
            }

            DataReader reader = args.GetDataReader();

            byte[] data = new byte[reader.UnconsumedBufferLength];
            reader.ReadBytes(data);

            EndpointInformation message = EndpointInformation.Deserialize(data);

            if (message != null)
            {
                // Did message originate from a server?
                if (message.Type == EndpointType.Server)
                {
                    ServerDiscovered?.Invoke(this, message);
                }
            }
        }