Exemplo n.º 1
0
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        public void MessageReceived(Socket socket, ReceivedEventArgs e)
        {
            string      info, ip = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString();
            int         port        = ((IPEndPoint)socket.RemoteEndPoint).Port;
            ClientModel clientModel = this.tcpServer_Watchdog.ResolveSocket(ip, port);

            if (clientModel == null)
            {
                info = Functions.AddTimeToMessage("客户端为空,怎么就收到消息了呢?不管咋说,消息是这个:" + e.ReceivedString);
                this.tcp_info_receive = info;
                return;
            }
            if (clientModel.ClientType == ClientType.None)
            {
                ClientType clientType = ClientModel.AnalyzeClientType(e.ReceivedString);
                clientModel.ClientType = clientType;
            }
            info = Functions.AddTimeToMessage(string.Format("{0}:{1} -> 从类型为{2}的客户端 {3}:{4} 接收到数据:{5}", this.tcpServer_Watchdog.ServerIp, this.tcpServer_Watchdog.ServerPort, clientModel.ClientType.ToString(), ip, port, e.ReceivedString));
            this.tcp_info_receive = info;
        }