Example #1
0
        protected override void Run()
        {
            while (!IsTerminateFlagSet() && m_SendEvent != null)
            {
                m_SendEvent.WaitOne();
                if(m_packetList.Switch() == false)return;

                while (m_packetList.m_OutList.Count > 0)
                {
                    NetPackageOut pkg = m_packetList.m_OutList[0];
                    //pkg.pack();
                    packoutCmd = pkg;
                    m_packetList.m_OutList.RemoveAt(0);

                    if (m_tcpClient != null && m_tcpClient.Connected)
                    {
                        try
                        {
                            // encode
                            byte[] buff = pkg.GetBuffer();

//                             if (NetWork.DEENCODE)
//                             {
//                                 // 加密编码
//                                 //Engine.Encrypt.Encode(ref buff);
//                             }

                            NetStream.Write(buff, 0, (int)pkg.Length);
                            NetStream.Flush();

                            if (m_tcpClient == null || !m_tcpClient.Connected)
                            {
                                EnqueErrorPack(pkg);
                            }
                        }
                        catch (IOException e)
                        {
                          //  Log.Error("发包{0}异常: {1}", pkg.getCode(), e.ToString());
                            EnqueErrorPack(pkg);
                        }
                    }
                    else
                    {
                        // Utility.Log.Trace("断线发包: code=" + pkg.getCode().ToString());
                        EnqueErrorPack(pkg);
                        break;
                    }
                } // end while(m_packetList.m_OutList.Count > 0)
            }//end while
        }
Example #2
0
 /// <summary>
 /// 准备将数据包发送
 /// </summary>
 /// <param name="p"></param>
 public void Send(NetPackageOut p)
 {
     m_packetList.Push(p);
     m_SendEvent.Set();  //将事件状态设置为终止状态,允许一个或多个等待线程继续
 }
Example #3
0
 /// <summary>
 /// 发包出错 进入缓存
 /// </summary>
 /// <param name="pkg"></param>
 public void EnqueErrorPack(NetPackageOut pkg)
 {
     packout.Enqueue(pkg);
 }
Example #4
0
        public void SendMsg(NetPackageOut pkg)
        {
            if (this.IsConnected())
            {
                if (m_sender != null)
                {
                    m_sender.Send(pkg);

                    if (m_NetLinkMonitor != null)
                    {
                        m_NetLinkMonitor.OnSend(pkg);
                    }
                }
            }
            else
            {
              //  Utility.Log.Trace("已经断开连接,发包错误,包进入缓存");
                if (m_sender != null)
                {
                    m_sender.EnqueErrorPack(pkg);
                }
            }
        }