Exemplo n.º 1
0
 void UDPMulticastMessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
 {
     try
     {
         uint   stringLength = eventArguments.GetDataReader().UnconsumedBufferLength;
         string message      = eventArguments.GetDataReader().ReadString(stringLength);
         ParseMessage(message);
     }
     catch (Exception exception)
     {
         SocketErrorStatus socketError = SocketError.GetStatus(exception.HResult);
         if (socketError == SocketErrorStatus.ConnectionResetByPeer)
         {
         }
         else if (socketError != SocketErrorStatus.Unknown)
         {
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 2
0
        private async void Multicast_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            handlingPacket = true;
            var reader = args.GetDataReader();

            // check to see if the received data matches the expected message
            uint length = reader.UnconsumedBufferLength;

            OneWireEventSource.Log.Debug("DEBUG: packet.length=" + length);
            OneWireEventSource.Log.Debug("DEBUG: expecting=" + expectedMessage.Length);
            try
            {
                if (length == expectedMessage.Length)
                {
                    bool dataMatch = true;
                    for (int i = 0; dataMatch && i < length; i++)
                    {
                        dataMatch = (expectedMessage[i] == reader.ReadByte());
                    }
                    // check to see if we received the expected message
                    if (dataMatch)
                    {
                        OneWireEventSource.Log.Debug("DEBUG: packet match, replying");

                        // send return message
                        using (var writer = new DataWriter(socket.OutputStream))
                        {
                            writer.WriteBytes(returnMessage);
                            await writer.StoreAsync();

                            // we return before the packet goes out, that's fine
                        }
                    }
                }
                else
                {
                    OneWireEventSource.Log.Critical("Unknown packet length recieved: " + length);
                }
            }
            catch (System.IO.IOException)
            {
                // drain
                ;
            }
            finally
            {
                handlingPacket = false;
                waitPacketDone.Set();
            }
        }
 async void UDPMessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
 {
     try
     {
         uint   stringLength = eventArguments.GetDataReader().UnconsumedBufferLength;
         string message      = eventArguments.GetDataReader().ReadString(stringLength);
         await ParseMessage(message);
     }
     catch (Exception exception)
     {
         SocketErrorStatus socketError = SocketError.GetStatus(exception.HResult);
         if (socketError == SocketErrorStatus.ConnectionResetByPeer)
         {
         }
         else if (socketError != SocketErrorStatus.Unknown)
         {
         }
         else
         {
             System.Diagnostics.Debug.WriteLine("Exception while receiving UDP packet:" + exception.Message);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Event consumer for udp message received. Raises OSCPacketReceivedEvent.
        /// </summary>
        public void udpClient_MessageReceived(object sender, DatagramSocketMessageReceivedEventArgs e)
        {
            DataReader reader = e.GetDataReader();

            if (reader.UnconsumedBufferLength > 0)
            {
                byte[] bytes = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(bytes);
                OSCPacketReceivedEventArgs args = new OSCPacketReceivedEventArgs();
                args.packet = OSCPacket.Unpack(bytes);
                OnOSCPacketReceivedEvent(args);
                Debug.WriteLine(args.packet.ToString());
            }
        }
Exemplo n.º 5
0
        private async void _socketUdp_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                uint   stringLength    = args.GetDataReader().UnconsumedBufferLength;
                string receivedMessage = args.GetDataReader().ReadString(stringLength);

                if (receivedMessage.ToLower().Equals(CommunicationCommands.MCCConnection.ToLower()))
                {
                    IOutputStream outputStream = await _socketUdp.GetOutputStreamAsync(
                        args.RemoteAddress,
                        args.RemotePort);

                    MCCConnection = new ConnectionInfo(args.RemoteAddress.ToString(), args.RemotePort, outputStream);
                }

                MessageReceived?.Invoke(this, new CommunicationMsg(receivedMessage));
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
Exemplo n.º 6
0
        void MessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
        {
            try
            {
                // Interpret the incoming datagram's entire contents as a string.
                uint   stringLength    = eventArguments.GetDataReader().UnconsumedBufferLength;
                string receivedMessage = eventArguments.GetDataReader().ReadString(stringLength);

                NotifyUserFromAsyncThread(
                    "Received data from remote peer: \"" +
                    receivedMessage + "\"",
                    NotifyType.StatusMessage);
            }
            catch (Exception exception)
            {
                SocketErrorStatus socketError = SocketError.GetStatus(exception.HResult);
                if (socketError == SocketErrorStatus.ConnectionResetByPeer)
                {
                    // This error would indicate that a previous send operation resulted in an
                    // ICMP "Port Unreachable" message.
                    NotifyUserFromAsyncThread(
                        "Peer does not listen on the specific port. Please make sure that you run step 1 first " +
                        "or you have a server properly working on a remote server.",
                        NotifyType.ErrorMessage);
                }
                else if (socketError != SocketErrorStatus.Unknown)
                {
                    NotifyUserFromAsyncThread(
                        "Error happened when receiving a datagram: " + socketError.ToString(),
                        NotifyType.ErrorMessage);
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 7
0
        private async void _socket_OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs e)
        {
            var    reader  = e.GetDataReader();
            string message = reader.ReadString(reader.UnconsumedBufferLength);

            Logger.Trace("Message from {0}:{1}:\n{2}", e.RemoteAddress.RawName, e.RemotePort, message);

            IOutputStream outputStream = await sender.GetOutputStreamAsync(e.RemoteAddress, e.RemotePort);

            Received(this, new PeerCommandEventArgs
            {
                Data = message,
                Peer = new RemotePeer(_serializer, this, outputStream, e.RemoteAddress, e.RemotePort),
            });
        }
        private async void UdpListener_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            Log(ServerOptions.Verbosity.Verbose, $"SERVER: UDP: Got incoming message");
            Stats.IncrementNConnections();

            var dr         = args.GetDataReader();
            var remoteHost = args.RemoteAddress;
            var remotePort = args.RemotePort;
            var os         = await sender.GetOutputStreamAsync(remoteHost, remotePort);

            //var dw = new DataWriter(sender.OutputStream);
            var   dw = new DataWriter(os);
            Task  t  = EchoUdpAsync("UDP", dr, dw);
            await t;
        }
Exemplo n.º 9
0
 private void ClientOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
 {
     try
     {
         var dataReader = args.GetDataReader();
         var endpoint   = new IPEndPoint(IPAddress.Parse(args.RemoteAddress.RawName), int.Parse(args.RemotePort));
         var buffer     = new byte[dataReader.UnconsumedBufferLength];
         dataReader.ReadBytes(buffer);
         OnMessageReceived(buffer, endpoint);
     }
     catch
     {
         // ignored
     }
 }
Exemplo n.º 10
0
        private void OnDatagramSocketMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            Log("Datagram message received");
            if (args == null)
            {
                return;
            }
            string data;

            using (var reader = args.GetDataReader())
            {
                data = reader.ReadString(reader.UnconsumedBufferLength);
            }
            Log(data);
            Task task = GetDeviceDescriptionAsync(data, args.LocalAddress);
        }
Exemplo n.º 11
0
 private static void UdpClient_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
 {
     using (var reader = args.GetDataReader())
     {
         reader.ByteOrder = ByteOrder.LittleEndian;
         type             = reader.ReadInt64();
         userID           = reader.ReadInt64();
         challenge        = new byte[16];
         reader.ReadBytes(challenge);
         var padding = new byte[32];
         reader.ReadBytes(padding);
         sender.Dispose();
         udpClient = null;
         waiter.Set();
     }
 }
Exemplo n.º 12
0
 private void OnSocketMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
 {
     try
     {
         using (var reader = args.GetDataReader())
         {
             byte[] response = new byte[48];
             reader.ReadBytes(response);
             _resultCompletionSource.TrySetResult(ParseNetworkTime(response));
         }
     }
     catch (Exception ex)
     {
         _resultCompletionSource.TrySetException(ex);
     }
 }
Exemplo n.º 13
0
        private void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            DataReader networkDataReader = args.GetDataReader();

            int len = networkDataReader.ReadInt32();

            byte[] data = new byte[len];
            networkDataReader.ReadBytes(data);

            NetInMessage message = new NetInMessage(data);

            lock (lockObj)
            {
                m_incomingMessageQueue.Enqueue(message);
            }
        }
Exemplo n.º 14
0
        private void HandleIncomingMessages(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs e)
        {
            //(await e.RemoteAddress.IPInformation.NetworkAdapter.GetConnectedProfileAsync()).GetNetworkNames();
            if (hostNames != null && hostNames.Contains(e.RemoteAddress.ToString()))
            {
                return;
            }
            var remote = e.RemoteAddress;
            var local  = e.LocalAddress;
            var reader = e.GetDataReader();

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

            if (msg.Type == MessageType.DeviceStateService)
            {
                ProcessDeviceDiscoveryMessage(e.RemoteAddress, e.RemotePort, msg);
            }
            else
            {
                if (taskCompletions.ContainsKey(msg.Source))
                {
                    var tcs = taskCompletions[msg.Source];
                    tcs(msg);
                }

                //else if (msg.Type.ToString().StartsWith("State"))
                //{
                //}
                //else if (msg.Type == MessageType.DeviceAcknowledgement)
                //{
                //	if (taskCompletions.ContainsKey(msg.Source))
                //	{
                //		var tcs = taskCompletions[msg.Source];
                //		if (!tcs.Task.IsCompleted)
                //			tcs.SetResult(msg);
                //	}
                //}
                else
                {
                    //TODO
                }
            }
            System.Diagnostics.Debug.WriteLine("Received from {0}:{1}", remote.RawName,
                                               string.Join(",", (from a in data select a.ToString("X2")).ToArray()));
        }
Exemplo n.º 15
0
        private static byte[] ReadPackageFromMessage(DatagramSocketMessageReceivedEventArgs message)
        {
            using (var reader = message.GetDataReader())
            {
                if (reader.UnconsumedBufferLength != LightPiProtocol.PackageLength)
                {
                    // Ignore all messages with a wrong package size.
                    Debug.WriteLine($"Received invalid message with a length of {reader.UnconsumedBufferLength} bytes");
                    return(null);
                }

                var buffer = new byte[LightPiProtocol.PackageLength];
                reader.ReadBytes(buffer);

                return(buffer);
            }
        }
Exemplo n.º 16
0
 private void HandleMessage(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs e)
 {
     try
     {
         using (var dataReader = e.GetDataReader())
         {
             //dataReader.ByteOrder = ByteOrder.BigEndian;
             byte[] packet = new byte[dataReader.UnconsumedBufferLength];
             dataReader.ReadBytes(packet);
             OnMessageReceived(packet);
         }
     }
     catch (Exception exception)
     {
         Debug.WriteLine(exception);
     }
 }
Exemplo n.º 17
0
 void socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
 {
     try
     {
         DataReader rd     = args.GetDataReader();
         uint       length = rd.UnconsumedBufferLength;
         byte[]     buffer = new byte[length];
         rd.ReadBytes(buffer);
         processData(buffer);
     }
     catch (Exception e)
     {
         Debug.Log(e.ToString());
         Debug.Log(SocketError.GetStatus(e.HResult).ToString());
         return;
     }
 }
        private void UdpMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                using (DataReader dataReader = args.GetDataReader())
                {
                    IBuffer buffer = dataReader.ReadBuffer(dataReader.UnconsumedBufferLength);
                    byte[]  bytes  = buffer.ToArray();

                    Debug.WriteLine($"UDP receiving (from \"{args.RemoteAddress}\"): {string.Join(", ", bytes.Select(x => x.ToString("X2")))} ({bytes.Length} byte(s)).");
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine("UDP receive exception: " + exception);
            }
        }
Exemplo n.º 19
0
        //------------------------------------------------------------------------------------------------------------------------
#if UNIVERSAL
        private void _sock_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs e)
        {
            lock (this)
            {
                var address = e.RemoteAddress.ToString();
                var port    = int.Parse(e.RemotePort);

                //cleanup old
                CleanUp();

                using (var reader = e.GetDataReader())
                {
                    var data = reader.DetachBuffer().ToArray().Skip(2).ToArray();
                    HandleNewPacket(data, address);
                }
            }
        }
Exemplo n.º 20
0
            private void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
            {
                //Logger.Trace("OnMessageReceived: endpoint = {0}, port = {1}", args.RemoteAddress, args.RemotePort);

                var reader = args.GetDataReader();
                var count  = reader.UnconsumedBufferLength;
                var data   = new byte[count];

                reader.ReadBytes(data);
                lock (m_messages)
                {
                    m_messages.Add(new Message {
                        Data = data
                    });
                }
                m_messageReceivedEvent.Set();
            }
Exemplo n.º 21
0
 public void OnDatagramMessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args)
 {
     try
     {
         var reader   = args.GetDataReader();
         var length   = reader.UnconsumedBufferLength;
         var received = reader.ReadString(length);
         foreach (var ch in received)
         {
             if (ch == '\r' || ch == '\n')
             {
                 if (builder.Length > 0)
                 {
                     var logline = builder.ToString();
                     var m       = SyslogRegex.Match(logline);
                     if (m.Success)
                     {
                         if (ushort.TryParse(m.Groups["pri"].Value, out ushort pr))
                         {
                             var f   = (Facility)(pr >> 3);
                             var p   = (Priority)(pr & 7);
                             var tag = m.Groups["tag"].Value as string;
                             Received?.Invoke(this, new MessageEventArgs(f, p, DateTime.Now, tag, m.Groups["msg"].Value));
                         }
                         else
                         {
                             Received?.Invoke(this, new MessageEventArgs(logline));
                         }
                     }
                     else
                     {
                         Received?.Invoke(this, new MessageEventArgs(logline));
                     }
                     builder.Clear();
                 }
             }
             else
             {
                 builder.Append(ch);
             }
         }
     } catch (Exception)
     {
     }
 }
Exemplo n.º 22
0
    async void udpMessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args)
    {
        if (!targetIPReady && !connected && !trashUDP)
        {
            trashUDP = true;
            DataReader reader     = args.GetDataReader();
            uint       len        = reader.UnconsumedBufferLength;
            string     msg        = reader.ReadString(len);
            string     remoteHost = args.RemoteAddress.DisplayName;
            targetIP      = msg;
            targetIPReady = true;
            await listenerSocket.CancelIOAsync();

            listenerSocket.MessageReceived -= udpMessageReceived;
            listenerSocket.Dispose();
            listenerSocket = null;
        }
    }
Exemplo n.º 23
0
        private void UDPReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args)
        {
            DataReader reader = args.GetDataReader();

            try
            {
                uint   len  = reader.UnconsumedBufferLength;
                byte[] data = new byte[len];
                reader.ReadBytes(data);
                _udpCallback(socket, data);
            } catch (Exception e)
            {
                SocketErrorStatus socketError = SocketError.GetStatus(e.HResult);
                throw;
            }

            reader.Dispose();
        }
Exemplo n.º 24
0
        private void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            var  dataReader = args.GetDataReader();
            uint count      = dataReader.UnconsumedBufferLength;

            if (count > 0)
            {
                byte[] data = new byte[count];
                dataReader.ReadBytes(data);
                _incomingData.Enqueue(
                    new IncomingData
                {
                    EndPoint = new NetEndPoint(args.RemoteAddress, args.RemotePort),
                    Data     = data
                });
                _receiveWaiter.Set();
            }
        }
        async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            if (ListenerMessageEvent != null)
            {
                var reader = new StreamReader(args.GetDataStream().AsStreamForRead());
                var data   = await reader.ReadLineAsync();

                ListenerMessageEvent(data, args.RemoteAddress.DisplayName);
            }

            if (ListenerByteEvent != null)
            {
                var readData = args.GetDataReader();
                var byteData = new byte[readData.UnconsumedBufferLength];
                readData.ReadBytes(byteData);
                ListenerByteEvent(byteData, args.RemoteAddress.DisplayName);
            }
        }
Exemplo n.º 26
0
        private static async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                var readPacket = args.GetDataReader();

                if (readPacket == null)
                {
                    Debug.WriteLine("DataReader is null");
                    return;
                }

                uint buffLen = readPacket.UnconsumedBufferLength;

                if (buffLen == 0)
                {
                    Debug.WriteLine("Buffer is empty");
                    return;
                }

                if (!App.isRPi)
                {
                    //GET FRAME
                    var buffer = readPacket.ReadBuffer(buffLen);
                    var stream = buffer.AsStream();
                    stream.Seek(0, SeekOrigin.Begin);
                    IRandomAccessStream photoStream = stream.AsRandomAccessStream();

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        BitmapImage frame = new BitmapImage();
                        await frame.SetSourceAsync(photoStream);
                        var currentPage     = ((ContentControl)Window.Current.Content).Content as Page;
                        var captureImage    = currentPage.FindName("captureFrame") as Image;
                        captureImage.Source = frame;
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MessageReceived() - " + ex.Message);
            }
        }
Exemplo n.º 27
0
        //private async void SocketOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        //{
        //    var result = args.GetDataStream();
        //    var resultStream = result.AsStreamForRead(1024);

        //    using (var reader = new StreamReader(resultStream))
        //    {
        //        var text = await reader.ReadToEndAsync();

        //    }
        //}

        private void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                var r = args.GetDataReader();
                var l = r.UnconsumedBufferLength;
                buffer = new byte[l];
                r.ReadBytes(buffer);
            }
            catch (Exception exception)
            {
                SocketErrorStatus socketError = Windows.Networking.Sockets.SocketError.GetStatus(exception.HResult);

                if (Windows.Networking.Sockets.SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    throw;
                }
            }
        }
Exemplo n.º 28
0
 private void UdpSocket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
 {
     try
     {
         var dr = args.GetDataReader();
         dr.InputStreamOptions = InputStreamOptions.Partial; // | InputStreamOptions.ReadAhead;
         var udpResult = ReadUdp(dr);
         UdpResults.Add(sender.Information.LocalPort, udpResult);
     }
     catch (Exception ex)
     {
         // This can happen when we send a packet to a correct host (like localhost) but with an
         // incorrect service. The packet will "bounce", resuluting in a MessageReceived event
         // but with an args with no real data.
         Stats.NExceptions++;
         var delta     = DateTime.UtcNow.Subtract(SocketStartTime).TotalSeconds;
         var udpResult = EchoResult.MakeFailed(ex, delta);
         UdpResults.Add(sender.Information.LocalPort, udpResult);
     }
 }
Exemplo n.º 29
0
        protected override void _socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            Debug.WriteLine(args.RemoteAddress.DisplayName);

            using (DataReader reader = args.GetDataReader())
            {
                MessageModel message = MessageModel.ToMessage(reader);
                //byte[] data = new byte[reader.UnconsumedBufferLength];
                //reader.ReadBytes(data);
                //MessageModel message = MessageModel.ToMessageFromEncrypted(data);

                switch (message.Type)
                {
                case MessageType.DeviceDetection:
                    ResponseDeviceDetection(message, args.RemoteAddress);
                    break;
                }
                MessageReceived?.Invoke(sender, message);
            }
        }
Exemplo n.º 30
0
        private void MessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                DataReader reader = args.GetDataReader();
                reader.InputStreamOptions = InputStreamOptions.Partial;
                uint   bytesRead = reader.UnconsumedBufferLength;
                String message   = reader.ReadString(bytesRead);

                playPage.DisplayMessages(name + " :Message received [" +
                                         args.RemoteAddress.DisplayName.ToString() + "]:" + args.RemotePort + ": " + message);

                SendMessage(IPAdress.LocalIPAddress() + " " + name, args.RemoteAddress.DisplayName.ToString(), portSender);
                reader.Dispose();
            }
            catch (Exception ex)
            {
                playPage.DisplayMessages(name + " :ERROR: Message received from:\n" + ex.ToString());
            }
        }
Exemplo n.º 31
0
        private void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
        {
            try
            {
                var connectionKey = GetConnectionKey(args.RemoteAddress, args.RemotePort);

                Connection connection;
                bool newConnection = false;
                lock (this.connectionCache)
                {
                    if (!this.connectionCache.TryGetValue(connectionKey, out connection))
                    {
                        connection = new Connection();
                        this.connectionCache.Add(connectionKey, connection);

                        newConnection = true;
                    }

                    connection.Touch();
                }

                var reader = args.GetDataReader();
                string received = reader.ReadString(reader.UnconsumedBufferLength);

                var msg = DeserializeInternalMessage(received);

                var connectMessage = msg as Model.ConnectMessage;
                if (connectMessage != null)
                {
                    if (newConnection)
                        Debug.WriteLine("New connection {0}:{1} from host {2}", args.RemoteAddress, args.RemotePort, connectMessage.HostId);

                    Debug.WriteLine("Connect from " + connectMessage.HostId);

                    lock (this.hostIdLookup)
                    {
                        this.hostIdLookup[connectMessage.HostId] = connectionKey;
                    }

                    connection.HostId = connectMessage.HostId;

                    // Send alive message
                    Task.Run(async () => await SendAliveAsync(connectMessage.HostId));
                }

                var payloadMessage = msg as Model.PayloadMessage;
                if (payloadMessage != null)
                {
                    object payloadObject = DeserializePayload(payloadMessage.Payload);

                    try
                    {
                        this.payloadReceivedAction?.Invoke(connection.HostId, payloadObject);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Exception while invoking callback with payload object " + ex.ToString());
                    }
                }
            }
            catch (Exception exception)
            {
                SocketErrorStatus socketError = SocketError.GetStatus(exception.HResult);
                if (socketError == SocketErrorStatus.ConnectionResetByPeer)
                {
                    // This error would indicate that a previous send operation resulted in an 
                    // ICMP "Port Unreachable" message.
                    //NotifyUserFromAsyncThread(
                    //    "Peer does not listen on the specific port. Please make sure that you run step 1 first " +
                    //    "or you have a server properly working on a remote server.",
                    //    NotifyType.ErrorMessage);
                }
                else if (socketError != SocketErrorStatus.Unknown)
                {
                    //NotifyUserFromAsyncThread(
                    //    "Error happened when receiving a datagram: " + socketError.ToString(),
                    //    NotifyType.ErrorMessage);
                }
                else
                {
                    throw;
                }
            }
        }