Наследование: IDisposable
Пример #1
0
 internal void OnReceived(ENetEvent eNetEvent)
 {
     // 将包放到缓存队列
     using (UPacket packet = new UPacket(eNetEvent.Packet))
     {
         byte[] bytes = packet.Bytes;
         this.RecvQueue.Enqueue(bytes);
     }
 }
Пример #2
0
        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;
        }
Пример #3
0
		internal void OnReceived(ENetEvent eNetEvent)
		{
			// 将包放到缓存队列
			using (UPacket packet = new UPacket(eNetEvent.Packet))
			{
				byte[] bytes = packet.Bytes;
				this.RecvQueue.Enqueue(bytes);
			}
			this.received();
		}
Пример #4
0
		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;
		}