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); }
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(); } }
internal void ReceivePkg(Packet pkg) { try { if (Received == null) return; Received(pkg); } catch (Exception ex) { log.Error("数据包处理出错.", ex); } }
public void SendPacket(Packet pkg) { m_sender.SendTcp(pkg); }
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); }
void m_socket_Received(Packet packet) { GamePacket gp = packet as GamePacket; if(gp != null) ReceivePacket(gp); }
public void SendPacket(Packet pack) { SessionManager.Instance.SendPacket(pack.session); }