示例#1
0
        public void PacketArrived(TcpServer TS)
        {
            string ServiceId = TS.ServiceID;
            ConcurrentQueue <TcpReceivedData> Qtrd = TS.TQ.Qtrd;
            List <TcpSocket> Ts = TS.Ts;
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;


            while (Qtrd.Count > 0)
            {
                TcpReceivedData trd = null;
                Qtrd.TryDequeue(out trd);
                if (trd != null)
                {
                    try
                    {
                        //注册&透传
                        Service.ServiceBussiness.RemoteCommand(trd.Data);
                        //Service.ServiceBussiness.Registered30(urd.Data);

                        //ASCII To String
                        string data = EnCoder.ByteArrayToHexStr(trd.Data); //Encoding.ASCII.GetString(trd.Data);
                        if (pd.GetDataState(data) == "01")
                        {
                            string STCD = pd.GetCode(data);
                            InsertNewSTCD(STCD, Service.ServiceEnum.NFOINDEX.TCP, TS);
                            bool B = false;
                            //更新socket列表的stcd、socket
                            TcpBussiness.UpdSocket(TS, trd.SOCKET, STCD, out B);
                            if (!B)
                            {
                                //上线
                                TcpBussiness.TcpConnected(TS, STCD);
                            }
                            //通知界面
                            ServiceBussiness.WriteQUIM("TCP", ServiceId, STCD, "接收数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);

                            PacketArrived(data, ServiceEnum.NFOINDEX.TCP, TS);
                        }
                        else
                        {
                            ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                    }
                    catch (Exception ex)
                    {
                        //通知界面
                        ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        log.Error(DateTime.Now + "包处理操作异常" + ex.ToString());
                    }
                }
            }
        }
示例#2
0
        public void PacketArrived(TcpServer TS)
        {
            string serviceID = TS.ServiceID;
            ConcurrentQueue <TcpReceivedData> qtrd = TS.TQ.Qtrd;
            List <TcpSocket> ts = TS.Ts;
            ConcurrentQueue <TcpSendData> qtsd = TS.TQ.Qtsd;

            while (qtrd.Count > 0)
            {
                TcpReceivedData tcpReceivedData = null;
                qtrd.TryDequeue(out tcpReceivedData);
                if (tcpReceivedData != null)
                {
                    string a    = "";
                    string s    = "";
                    string STCD = GetSTCD(tcpReceivedData.Data, out a, out s);
                    if (a == "H")
                    {
                        InsertNewSTCD(STCD, ServiceEnum.NFOINDEX.TCP, TS);
                        bool flag = false;
                        TcpBussiness.UpdSocket(TS, tcpReceivedData.SOCKET, STCD, out flag);
                    }
                    else
                    {
                        if (a == "C")
                        {
                            IEnumerable <TcpSocket> source =
                                from t in ts
                                where t.STCD == STCD && t.TCPSOCKET != null
                                select t;
                            List <TcpSocket> list = source.ToList <TcpSocket>();
                            if (list.Count <TcpSocket>() > 0)
                            {
                                foreach (TcpSocket current in list)
                                {
                                    current.TCPSOCKET.Send(Encoding.ASCII.GetBytes(s));
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public void PacketArrived(TcpService.TcpServer TS)
        {
            string ServiceId = TS.ServiceID;
            ConcurrentQueue <TcpReceivedData> Qtrd = TS.TQ.Qtrd;
            List <TcpSocket> Ts = TS.Ts;
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;


            while (Qtrd.Count > 0)
            {
                TcpReceivedData trd = null;
                Qtrd.TryDequeue(out trd);
                if (trd != null)
                {
                    //Frame[] frames = null;

                    try
                    {
                        //注册&透传
                        Service.ServiceBussiness.RemoteCommand(trd.Data);
                        //Service.ServiceBussiness.Registered30(urd.Data);

                        //ASCII To String
                        string   STR  = Encoding.ASCII.GetString(trd.Data);
                        string[] STRs = STR.Split(new string[] { "##" }, StringSplitOptions.None);
                        if (STRs.Length > 0)
                        {
                            foreach (var item in STRs)
                            {
                                if (item != "")
                                {
                                    string STCD = pd.GetMN(item);
                                    InsertNewSTCD(STCD, Service.ServiceEnum.NFOINDEX.TCP, TS);
                                    bool B = false;
                                    //更新socket列表的stcd、socket
                                    TcpBussiness.UpdSocket(TS, trd.SOCKET, STCD, out B);
                                    if (!B)
                                    {
                                        //上线
                                        TcpBussiness.TcpConnected(TS, STCD);
                                    }
                                    //通知界面
                                    ServiceBussiness.WriteQUIM("TCP", ServiceId, STCD, "接收数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);

                                    PacketArrived(item, ServiceEnum.NFOINDEX.TCP, TS);
                                }
                            }
                        }
                        else
                        {
                            ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        }
                    }
                    catch (Exception ex)
                    {
                        //通知界面
                        ServiceBussiness.WriteQUIM("TCP", ServiceId, "", "接收异常数据", trd.Data, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text);
                        log.Error(DateTime.Now + "包处理操作异常" + ex.ToString());
                    }
                }
            }
            //throw new NotImplementedException();
        }