예제 #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
파일: JSocket.cs 프로젝트: W8023Y2014/jsion
 internal void ReceivePkg(Packet pkg)
 {
     try
     {
         if (Received == null) return;
         Received(pkg);
     }
     catch (Exception ex)
     {
         log.Error("数据包处理出错.", ex);
     }
 }
예제 #4
0
파일: JSocket.cs 프로젝트: W8023Y2014/jsion
 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);
 }