Exemplo n.º 1
0
        /// <summary>
        /// 接收到服务器的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void ControllerServer_DatagramReceived(
            object sender, TcpDatagramReceivedEventArgs <byte[]> e)
        {
            try
            {
                if (e.TcpClient != null)
                {
                    if (RemoteHost == "" || RemoteHost == null)
                    {
                        RemoteHost = ((IPEndPoint)e.TcpClient.Client.RemoteEndPoint).Address.ToString();
                    }
                    if (RemotePort == "" || RemotePort == null)
                    {
                        RemotePort = ((IPEndPoint)e.TcpClient.Client.RemoteEndPoint).Port.ToString();
                    }
                }

                //处理数据
                JsonInterFace.Parse(e.Datagram, RemoteHost, RemotePort);
            }
            catch (Exception ex)
            {
                if (Parameters.LogStatus == 0)
                {
                    JsonInterFace.IODataHelper.SaveLogs(DateTime.Now.ToString(), "接收服务端数据异常", ex.Message, ex.StackTrace);
                }
                else
                {
                    Parameters.PrintfLogsExtended("接收服务端数据异常", ex.Message, ex.StackTrace);
                }
            }
        }