Example #1
0
        public bool Receive(out ENetPacket packet)
        {
            byte channel = 0;

            Native.ENetPacket *native = LibENet.PeerReceive(Unsafe, &channel);

            if (((IntPtr)native) == IntPtr.Zero)
            {
                packet = null;
                return(false);
            }

            packet = new ENetPacket(native, channel);
            LibENet.PacketDestroy(native);
            return(true);
        }
Example #2
0
        /// <summary>
        /// Attempts to dequeue any incoming queued packet.
        /// </summary>
        /// <param name="packet">Received packet if return value is true</param>
        /// <param name="channelId">Receiver channel if return value is true</param>
        /// <returns>Return true if packet received otherwise false</returns>
        public bool TryReceive(out ENetPacket packet, out byte channelId)
        {
            ThrowIfNull();

            byte chnl         = 0;
            var  resultPacket = LibENet.PeerReceive(m_Native, &chnl);

            if (resultPacket == null)
            {
                channelId = 0;
                packet    = default;
                return(false);
            }
            else
            {
                channelId = chnl;
                packet    = new ENetPacket(resultPacket);
                return(true);
            }
        }