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); } } } }
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); } } }