Exemplo n.º 1
0
        public void AddContactDataIntoBuffer(IList <ContactData> contactDatas, string serverIP, int port, ServerType serverType)
        {
            ContactDataWithServer contactDataWithServer;

            if (string.IsNullOrEmpty(serverIP))
            {
                return;
            }

            if (contactDatas == null || contactDatas.Count <= 0)
            {
                return;
            }

            for (int i = 0; i < contactDatas.Count; i++)
            {
                contactDataWithServer             = new ContactDataWithServer();
                contactDatas[i].ContactDataID     = Guid.NewGuid().ToString();
                contactDataWithServer.ContactData = contactDatas[i];
                contactDataWithServer.ServerIP    = serverIP;
                contactDataWithServer.ServerPort  = port;
                contactDataWithServer.ServerType  = serverType;
                GetUsingContactDataBuffer.Add(contactDataWithServer);
            }
        }
Exemplo n.º 2
0
        private void HandlerReSend()
        {
            while (IsRunning)
            {
                if (exeContactDataBufferKeys.Count > 0)
                {
                    int i = exeContactDataBuffer.Count - 1;
                    while (i >= 0)
                    {
                        DataWithServer item = exeContactDataBuffer[i];
                        if (item != null)
                        {
                            if (item.IsDelete)
                            {
                                exeContactDataBuffer.Remove(item);
                                i--;
                                continue;
                            }

                            if (item.SendTime.CompareTo(DateTime.Now.AddSeconds(-reSendSec).ToString(CommonFlag.F_DateTimeFormat)) < 0)
                            {
                                exeContactDataBufferKeys.Remove(item.SendID);
                                exeContactDataBuffer.Remove(item);
                                if (item.ReCount < reSendCount)
                                {
                                    GetUsingContactDataBuffer.Add(item);
                                }
                                else
                                {
                                    //base.LogTool.Log("未发送成功的数据包 item.MsgID:" + item.MsgID + " item.SendID:" + item.SendID + " item.Sort:" + item.Sort.ToString() + "item.ContactData" + item.ContactData.Length);
                                    HandleError(item.MsgID);
                                }
                            }
                        }
                        //else
                        //{
                        //    base.LogTool.Log("错误的空数据");
                        //}

                        i--;
                    }
                }
                Thread.Sleep(sendContactDataDelay);
            }
        }
Exemplo n.º 3
0
        public void SendMsg(string MsgID, byte[] data, string serverIP, int port)
        {
            DataWithServer contactDataWithServer;

            if (string.IsNullOrEmpty(serverIP))
            {
                return;
            }

            if (data == null || data.Length <= 0)
            {
                return;
            }

            if (data.Length > eachSendCount)
            {
                //大文件 分开发
                byte AllCount = (byte)Math.Ceiling(((double)data.Length) / ((double)eachSendCount));
                for (int i = 1; i <= 255 && i <= AllCount; i++)
                {
                    contactDataWithServer             = new DataWithServer();
                    contactDataWithServer.ServerIP    = serverIP;
                    contactDataWithServer.ServerPort  = port;
                    contactDataWithServer.Sort        = (byte)i;
                    contactDataWithServer.SendID      = Guid.NewGuid().ToString("N");
                    contactDataWithServer.MsgID       = MsgID;
                    contactDataWithServer.AllCount    = AllCount;
                    contactDataWithServer.ContactData = data.Skip((i - 1) * eachSendCount).Take(eachSendCount).ToArray();
                    GetUsingContactDataBuffer.Add(contactDataWithServer);
                }
            }
            else
            {
                contactDataWithServer             = new DataWithServer();
                contactDataWithServer.ServerIP    = serverIP;
                contactDataWithServer.ServerPort  = port;
                contactDataWithServer.SendID      = Guid.NewGuid().ToString("N");
                contactDataWithServer.MsgID       = MsgID;
                contactDataWithServer.Sort        = 0;
                contactDataWithServer.AllCount    = 0;
                contactDataWithServer.ContactData = data;
                GetUsingContactDataBuffer.Add(contactDataWithServer);
            }
        }
Exemplo n.º 4
0
        public void AddContactDataIntoBuffer(ContactData contactData, string serverIP, int port, ServerType serverType)
        {
            ContactDataWithServer contactDataWithServer;

            if (string.IsNullOrEmpty(serverIP))
            {
                return;
            }

            if (contactData == null)
            {
                return;
            }

            contactDataWithServer             = new ContactDataWithServer();
            contactData.ContactDataID         = Guid.NewGuid().ToString();
            contactDataWithServer.ContactData = contactData;
            contactDataWithServer.ServerIP    = serverIP;
            contactDataWithServer.ServerPort  = port;
            contactDataWithServer.ServerType  = serverType;
            GetUsingContactDataBuffer.Add(contactDataWithServer);
        }
Exemplo n.º 5
0
        protected override byte[] HandleRecived(byte[] data, T token)
        {
            string SendID = Encoding.UTF8.GetString(data, 0, 32);

            //传输出去的数据 回传响应
            if (exeContactDataBufferKeys.Contains(SendID))
            {
                exeContactDataBufferKeys.Remove(SendID);
                //tempj++;
                //base.LogTool.Log("接受回传响应数据包:" + SendID + "    " + tempj.ToString());
                int i = exeContactDataBuffer.Count - 1;
                while (i >= 0)
                {
                    DataWithServer tempdata = exeContactDataBuffer[i];
                    if (tempdata.SendID == SendID)
                    {
                        tempdata.IsDelete = true;
                        break;
                    }
                    i--;
                }

                return(null);
            }
            else
            {
                //空数据包
                if (data.Length <= 66)
                {
                    return(null);
                }

                //新数据
                //if (data.Length < 64)
                //{
                //    base.LogTool.Log("异常数据包:" + SendID);
                //    return null;
                //}

                byte[] returnbyte;
                if (data[64] > 0)
                {
                    returnbyte = HandleReadBuffer(data.Skip(64).ToArray(), Encoding.UTF8.GetString(data, 32, 32), token);
                }
                else
                {
                    returnbyte = HandleRecivedMessage(data.Skip(66).ToArray(), token);
                }
                if (returnbyte == null || returnbyte.Length <= 0)
                {
                    return(data.Take(32).ToArray());
                }

                DataWithServer contactDataWithServer = new DataWithServer();
                contactDataWithServer             = new DataWithServer();
                contactDataWithServer.ServerIP    = token.IP;
                contactDataWithServer.ServerPort  = token.Port;
                contactDataWithServer.SendID      = SendID;
                contactDataWithServer.MsgID       = Encoding.UTF8.GetString(data, 32, 32);
                contactDataWithServer.Sort        = data[65];
                contactDataWithServer.AllCount    = 0;
                contactDataWithServer.ContactData = null;
                GetUsingContactDataBuffer.Add(contactDataWithServer);

                return(null);
            }
        }