Esempio n. 1
0
        ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
        ///<param name="data">数据包</param>
        public void Send(PacketManaged data)
        {
            UInt16 serverid = localserverid;
            UInt16 Appid = (UInt16)APPID.Authorization;
            if ((serverid > 0) && (Appid > 0))
            {
                 if (isAppOnline(serverid, Appid))
                 {
                    lock (Synsend)
                    {
                        //封装寄出地址
                        data.Sserverid = localserverid;
                        data.SAppid = app.id;
                        data.checktime.Add(DateTime.Now);

                        if (data.UnSerializedData != null) //对数据序列化
                        {
                            DateTime date1 = DateTime.Now;
                            MemoryStream stream = new MemoryStream();
                            sformatter.Serialize(stream, data.UnSerializedData);
                            data.SerializedData = stream.GetBuffer();
                            data.UnSerializedData = null;
                            data.datasize = data.SerializedData.Length;
                        }
                        //
                        icPacket p = new icPacket();
                        p.Serverid = serverid;
                        p.Appid = (APPID)Appid;
                        p.dataid = Dataid;
                        p.data = data;
                        sendbuff.Enqueue(p);
                        if (sendbuffblocked)
                        {
                            sendbuffblocked = false;
                            sendbuffblockEvent.Set();
                        }
                    }
                 }
                 else
                 {
                     sendingpacket status = new sendingpacket();
                     status.data = data;
                     status.packetsize = 0;
                     status.sendtime = DateTime.Now;
                     status.outtime = DateTime.Now;
                     SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_APPDOWN, status);
                     ics_SendStatusEvent(e);
                 }
            }
            else
            {
                sendingpacket status = new sendingpacket();
                status.data = data;
                status.packetsize = 0;
                status.sendtime = DateTime.Now;
                status.outtime = DateTime.Now;
                SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_SERVERUNKOWN, status);
                ics_SendStatusEvent(e);
            }
        }
        protected override void ReOriginData(ReceivedobjEventArgs e)
        {
            base.ReOriginData(e);
            PacketManaged data = (PacketManaged)e.Data;

            if (data.SerializedData != null)
            {
                MemoryStream stream = new MemoryStream(data.SerializedData);
                data.UnSerializedData = rformatter.Deserialize(stream);
                data.SerializedData   = null;
            }
        }
        ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
        ///<param name="data">数据包</param>
        public void Send(PacketManaged data)
        {
            UInt16 serverid = data.Sserverid;
            UInt16 Appid    = (UInt16)data.SAppid;

            if ((serverid > 0) && (Appid > 0))
            {
                if (isAppOnline(serverid, (ushort)Appid))
                {
                    lock (Synsend)
                    {
                        data.checktime.Add(DateTime.Now);
                        icPacket p = new icPacket();
                        p.Serverid = serverid;
                        p.Appid    = (APPID)Appid;
                        p.dataid   = Dataid;
                        p.data     = data;
                        sendbuff.Enqueue(p);
                        if (sendbuffblocked)
                        {
                            sendbuffblocked = false;
                            sendbuffblockEvent.Set();
                        }
                    }
                }
                else
                {
                    sendingpacket status = new sendingpacket();
                    status.data       = data;
                    status.packetsize = 0;
                    status.sendtime   = DateTime.Now;
                    status.outtime    = DateTime.Now;
                    SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_APPDOWN, status);
                    ics_SendStatusEvent(e);
                }
            }
            else
            {
                sendingpacket status = new sendingpacket();
                status.data       = data;
                status.packetsize = 0;
                status.sendtime   = DateTime.Now;
                status.outtime    = DateTime.Now;
                SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_SERVERUNKOWN, status);
                ics_SendStatusEvent(e);
            }
        }
Esempio n. 4
0
 ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
 ///<param name="data">数据包</param>
 public void Send(PacketManaged data)
 {
     UInt16 serverid = data.Sserverid;
     UInt16 Appid = (UInt16)data.SAppid;
     if ((serverid > 0) && (Appid > 0))
     {
          if (isAppOnline(serverid, (ushort)Appid))
          {
             lock (Synsend)
             {
                 data.checktime.Add(DateTime.Now);
                 icPacket p = new icPacket();
                 p.Serverid = serverid;
                 p.Appid = (APPID)Appid;
                 p.dataid = Dataid;
                 p.data = data;
                 sendbuff.Enqueue(p);
                 if (sendbuffblocked)
                 {
                     sendbuffblocked = false;
                     sendbuffblockEvent.Set();
                 }
             }
          }
          else
          {
              sendingpacket status = new sendingpacket();
              status.data = data;
              status.packetsize = 0;
              status.sendtime = DateTime.Now;
              status.outtime = DateTime.Now;
              SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_APPDOWN, status);
              ics_SendStatusEvent(e);
          }
     }
     else
     {
         sendingpacket status = new sendingpacket();
         status.data = data;
         status.packetsize = 0;
         status.sendtime = DateTime.Now;
         status.outtime = DateTime.Now;
         SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_SERVERUNKOWN, status);
         ics_SendStatusEvent(e);
     }
 }
Esempio n. 5
0
        ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
        ///<param name="data">数据包</param>
        public void Send(PacketManaged data)
        {
            UInt16 serverid = localserverid;
            UInt16 Appid    = (UInt16)APPID.Authorization;

            if ((serverid > 0) && (Appid > 0))
            {
                if (isAppOnline(serverid, Appid))
                {
                    lock (Synsend)
                    {
                        //封装寄出地址
                        data.Sserverid = localserverid;
                        data.SAppid    = app.id;
                        data.checktime.Add(DateTime.Now);

                        if (data.UnSerializedData != null) //对数据序列化
                        {
                            DateTime     date1  = DateTime.Now;
                            MemoryStream stream = new MemoryStream();
                            sformatter.Serialize(stream, data.UnSerializedData);
                            data.SerializedData   = stream.GetBuffer();
                            data.UnSerializedData = null;
                            data.datasize         = data.SerializedData.Length;
                        }
                        //
                        icPacket p = new icPacket();
                        p.Serverid = serverid;
                        p.Appid    = (APPID)Appid;
                        p.dataid   = Dataid;
                        p.data     = data;
                        sendbuff.Enqueue(p);
                        if (sendbuffblocked)
                        {
                            sendbuffblocked = false;
                            sendbuffblockEvent.Set();
                        }
                    }
                }
                else
                {
                    sendingpacket status = new sendingpacket();
                    status.data       = data;
                    status.packetsize = 0;
                    status.sendtime   = DateTime.Now;
                    status.outtime    = DateTime.Now;
                    SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_APPDOWN, status);
                    ics_SendStatusEvent(e);
                }
            }
            else
            {
                sendingpacket status = new sendingpacket();
                status.data       = data;
                status.packetsize = 0;
                status.sendtime   = DateTime.Now;
                status.outtime    = DateTime.Now;
                SendStatusEventArgs e = new SendStatusEventArgs(SENDSTATUS.PACKET_SERVERUNKOWN, status);
                ics_SendStatusEvent(e);
            }
        }