示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        private void OnDataArrived(IAsyncResult result)
        {
            try
            {
                var readSize = _clientSocket.EndReceive(result);
                if (readSize > 0)
                {
                    var message = _buffer
                                  .Take(readSize)
                                  .ToArray();

                    Logger.Log(
                        LogStatusEnum.Info,
                        String.Format("Received data from {0}: {1}",
                                      EndPoint.Address.ToString(),
                                      message.ByteArrayToHexString()));

                    if (Watchdog.IsWatchdogPingMessage(message))
                    {
                        _clientSocket.Send(Watchdog.PONG_MSG);
                    }
                    else
                    {
                        _consumer.SetSocket(_clientSocket);
                        _consumer.Notify(message, EndPoint);
                    }

                    ReceiveNextPacket();
                }
            }
            catch (Exception e)
            {
                Logger.Log(LogStatusEnum.Error, "Error ocurred in data receiving." + e);
                if (e.Source != "System.Net.Sockets")
                {
                    ReceiveNextPacket();
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        private void OnDataArrived(IAsyncResult result)
        {
            try
            {
                IPEndPoint endPoint = null;

                var message = _udpClient
                              .EndReceive(result, ref endPoint);

                if (Watchdog.IsWatchdogPingMessage(message))
                {
                    _udpClient.Client.SendTo(Watchdog.PONG_MSG, endPoint);
                }
                else
                {
                    _consumer.SetSocket(_udpClient.Client);
                    _consumer.Notify(message, endPoint);
                }

                Logger.Log(
                    LogStatusEnum.Info,
                    String.Format("Received data from {0}: {1}",
                                  endPoint.Address.ToString(),
                                  message.ByteArrayToHexString()));

                ReceiveNextPacket();
            }
            catch (Exception e)
            {
                Logger.Log(LogStatusEnum.Error,
                           "Error ocurred in data receiving.", e);

                if (e.Source != "System.Net.Sockets")
                {
                    ReceiveNextPacket();
                }
            }
        }