Пример #1
0
        public PacketReader(JSocket socket, byte[] buffer)
        {
            m_socket = socket;
            m_buffer = buffer;

            ConfigPkg = m_socket.UsedPacket;
            m_cryptor = m_socket.ReceiveCryptor;
            if (m_cryptor == null) m_cryptor = new NoneCryptor();

            m_receiveAsyncEvent = new SocketAsyncEventArgs();

            m_receiveAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(receiveAsyncEvent_Completed);
        }
Пример #2
0
        public void SendTcp(Packet pkg)
        {
            if (pkg == null) return;

            if (!pkg.Writed)
            {
                pkg.WriteHeader();
                pkg.WriteData();
                pkg.Pack();
            }

            if (pkg.Length <= 0) return;

            if (m_socket.Socket.Connected == false)
            {
                return;
            }

            try
            {
                lock (m_pkgQueue.SyncRoot)
                {
                    m_pkgQueue.Enqueue(pkg);

                    if (m_sendingTcp)
                    {
                        return;
                    }

                    m_sendingTcp = true;
                }

                if (m_socket.EnableAsyncSend)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(sendAsyncImp), this);
                }
                else
                {
                    sendAsyncEvent_Completed(this, m_sendAsyncEvent);
                }
            }
            catch (Exception ex)
            {
                log.Error("数据包发送失败.", ex);
                m_socket.Disconnect();
            }
        }
Пример #3
0
 internal void ReceivePkg(Packet pkg)
 {
     try
     {
         if (Received == null) return;
         Received(pkg);
     }
     catch (Exception ex)
     {
         log.Error("数据包处理出错.", ex);
     }
 }
Пример #4
0
 public void SendPacket(Packet pkg)
 {
     m_sender.SendTcp(pkg);
 }
Пример #5
0
        void m_socket_Received(Packet packet)
        {
            GamePacket pkg = packet as GamePacket;
            if (ReceivedPacket != null)
            {
                try
                {
                    ReceivedPacket(pkg);
                }
                catch (Exception ex)
                {
                    log.Error("Handle packet error!", ex);
                }
            }

            try
            {
                OnReceivePacket(pkg);
            }
            catch (Exception ex)
            {
                log.Error("OnReceivePacket error!", ex);
            }
        }
 public override void HandleMessage(long session, byte[] buffer)
 {
     Packet pack = new Packet(new SessionBuffer(buffer, session));
     Net.NetEngine.Instance.SendPacket(pack);
 }
Пример #7
0
        void m_socket_Received(Packet packet)
        {
            GamePacket gp = packet as GamePacket;

            if(gp != null) ReceivePacket(gp);
        }
Пример #8
0
 public void SendPacket(Packet pack)
 {
     SessionManager.Instance.SendPacket(pack.session);
 }