コード例 #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);
            }
        }
コード例 #2
0
        /**********************************************************
         *
         * 发送模块
         *
         *********************************************************/

        //发送线程
        private void sendThreadStart()
        {
            MD5 md5Pro = new MD5CryptoServiceProvider();

            while (true)
            {
                try
                {
                    checkconnect();
                    sendblockEvent.WaitOne();
                    if (GetDataEvent != null)
                    {
                        icPacket packet = GetDataEvent(new EventArgs());

                        if (packet != null)
                        {
                            UInt16       Serverid  = packet.Serverid;
                            UInt16       Appid     = (UInt16)packet.Appid;
                            UInt32       Connectid = packet.Connectid;
                            UInt32       dataid    = packet.dataid;
                            object       data      = packet.data;
                            MemoryStream stream    = new MemoryStream();
                            sformatter.Serialize(stream, data);
                            byte[] d          = stream.GetBuffer();
                            byte[] md5        = md5Pro.ComputeHash(d);
                            byte[] p          = icParse.makeDataPacket(md5, d, serverid, (UInt16)app.id, Serverid, Appid, dataid);
                            UInt32 packetsize = (UInt32)p.Length;
                            lock (Synsendinglist)
                            {
                                sendingpacket sp = new sendingpacket();
                                sp.data       = packet.data;
                                sp.packetsize = packetsize;
                                sp.sendtime   = DateTime.Now;
                                double t = (sp.packetsize / MinNetSpeed);
                                if (t < MinTimeOut)
                                {
                                    t = MinTimeOut;
                                }
                                sp.outtime = sp.sendtime.AddSeconds(t);
                                sendinglist.Add(dataid, sp);
                            }
                            SendPakcet(p);
                            sendinglist[dataid].sendfinishtime = DateTime.Now;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (ExceptionEvent != null)
                    {
                        ExceptionEvent(e);
                    }
                }
            }
        }
コード例 #3
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);
            }
        }
コード例 #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);
     }
 }
コード例 #5
0
        ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
        ///<param name="data">数据包</param>
        public void Send(string stationid, object data)
        {
            UInt16 serverid = StationIdtoServerid(stationid);
            UInt16 Appid    = (UInt16)app.id;

            if ((serverid > 0) && (Appid > 0))
            {
                if (isAppOnline(serverid, Appid))
                {
                    lock (Synsend)
                    {
                        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);
            }
        }
コード例 #6
0
 ///<summary>异步发送数据,提交后立即返回,数据包在缓存中等待发送</summary>
 ///<param name="data">数据包</param>
 public void Send(string stationid, object data)
 {
     UInt16 serverid = StationIdtoServerid(stationid);
     UInt16 Appid = (UInt16)app.id;
     if ((serverid > 0) && (Appid > 0))
     {
         if (isAppOnline(serverid, Appid))
         {
             lock (Synsend)
             {
                 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);
     }
 }
コード例 #7
0
        public SendStatusEventArgs(SENDSTATUS status, sendingpacket packet)
        {
            this.m_packet = packet;
            this.m_status = status;
            switch (status)
            {
            case SENDSTATUS.PACKET_RECEIVED:
                m_msg = "数据已接收";
                break;

            case SENDSTATUS.PACKET_SERVERDOWN:
                m_msg = "发送到远程服务器失败,可能远程服务器未在线";
                break;

            case SENDSTATUS.PACKET_APPDOWN:
                m_msg = "发送到远程应用失败,可能远程应用未在线";
                break;

            case SENDSTATUS.PACKET_REJECT:
                m_msg = "拒绝接收数据包";
                break;

            case SENDSTATUS.PACKET_ERR:
                m_msg = "数据包传输错误";
                break;

            case SENDSTATUS.PACKET_TIMEOUT:
                m_msg = "数据包传输超时";
                break;

            case SENDSTATUS.PACKET_CANNOTCROSSAPP:
                m_msg = "没有给其他应用发送数据的权限";
                break;

            case SENDSTATUS.PACKET_SERVERUNKOWN:
                m_msg = "未知的stationid,或Appid错误";
                break;

            default:
                break;
            }
        }
コード例 #8
0
ファイル: Common.cs プロジェクト: burstas/purenessscopeserver
 public SendStatusEventArgs(SENDSTATUS status, sendingpacket packet)
 {
     this.m_packet = packet;
     this.m_status = status;
     switch (status)
     {
         case SENDSTATUS.PACKET_RECEIVED:
             m_msg = "数据已接收";
             break;
         case SENDSTATUS.PACKET_SERVERDOWN:
             m_msg = "发送到远程服务器失败,可能远程服务器未在线";
             break;
         case SENDSTATUS.PACKET_APPDOWN:
             m_msg = "发送到远程应用失败,可能远程应用未在线";
             break;
         case SENDSTATUS.PACKET_REJECT:
             m_msg = "拒绝接收数据包";
             break;
         case SENDSTATUS.PACKET_ERR:
             m_msg = "数据包传输错误";
             break;
         case SENDSTATUS.PACKET_TIMEOUT:
             m_msg = "数据包传输超时";
             break;
         case SENDSTATUS.PACKET_CANNOTCROSSAPP:
             m_msg = "没有给其他应用发送数据的权限";
             break;
         case SENDSTATUS.PACKET_SERVERUNKOWN:
             m_msg = "未知的stationid,或Appid错误";
             break;
         default:
             break;
     }
 }
コード例 #9
0
ファイル: icSocket.cs プロジェクト: jiagithub/PSS
        /**********************************************************
         * 
         * 发送模块
         * 
         *********************************************************/

        //发送线程
        private void sendThreadStart()
        {
            MD5 md5Pro = new MD5CryptoServiceProvider();
            while (true)
            {
                try
                {
                    checkconnect();
                    sendblockEvent.WaitOne();
                    if (GetDataEvent != null)
                    {
                        icPacket packet = GetDataEvent(new EventArgs());

                        if (packet != null)
                        {
                            UInt16 Serverid = packet.Serverid;
                            UInt16 Appid = (UInt16)packet.Appid;
                            UInt32 Connectid = packet.Connectid;
                            UInt32 dataid = packet.dataid;
                            object data = packet.data;
                            MemoryStream stream = new MemoryStream();
                            sformatter.Serialize(stream, data);
                            byte[] d = stream.GetBuffer();
                            byte[] md5 = md5Pro.ComputeHash(d);
                            byte[] p = icParse.makeDataPacket(md5, d, serverid, (UInt16)app.id, Serverid, Appid, dataid);
                            UInt32 packetsize = (UInt32)p.Length;
                            lock (Synsendinglist)
                            {
                                sendingpacket sp = new sendingpacket();
                                sp.data = packet.data;
                                sp.packetsize = packetsize;
                                sp.sendtime = DateTime.Now;
                                double t = (sp.packetsize / MinNetSpeed);
                                if (t < MinTimeOut) t = MinTimeOut;
                                sp.outtime = sp.sendtime.AddSeconds(t);
                                sendinglist.Add(dataid, sp);
                            }
                            SendPakcet(p);
                            sendinglist[dataid].sendfinishtime = DateTime.Now;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (ExceptionEvent != null) ExceptionEvent(e);
                }
            }
        }
コード例 #10
0
ファイル: ClientApp.cs プロジェクト: zh423328/PSS
        ///<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);
            }
        }