internal void OnReceived(ENetEvent eNetEvent) { // 将包放到缓存队列 using (UPacket packet = new UPacket(eNetEvent.Packet)) { byte[] bytes = packet.Bytes; this.RecvQueue.Enqueue(bytes); } }
public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable) { if (!isConnected) { sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags }); return; } UPacket packet = new UPacket(data, flags); NativeMethods.ENetPeerSend(this.PeerPtr, channelID, packet.PacketPtr); // enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除 packet.PacketPtr = IntPtr.Zero; }
internal void OnReceived(ENetEvent eNetEvent) { // 将包放到缓存队列 using (UPacket packet = new UPacket(eNetEvent.Packet)) { byte[] bytes = packet.Bytes; this.RecvQueue.Enqueue(bytes); } this.received(); }
public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable) { if (this.PeerPtr == IntPtr.Zero) { throw new Exception($"USocket 已经被Dispose,不能发送数据!"); } if (!isConnected) { sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags }); return; } UPacket packet = new UPacket(data, flags); NativeMethods.ENetPeerSend(this.PeerPtr, channelID, packet.PacketPtr); // enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除 packet.PacketPtr = IntPtr.Zero; }