Ejemplo n.º 1
0
        public ServerHost(Address address,
                          uint peerLimit         = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
                          uint channelLimit      = 0, uint incomingBandwidth = 0,
                          uint outgoingBandwidth = 0, bool enableCrc         = true)
        {
            if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException("peerLimit");
            }
            CheckChannelLimit(channelLimit);

            ENetAddress nativeAddress = address.Struct;

            this.host = NativeMethods.enet_host_create(
                ref nativeAddress, peerLimit,
                channelLimit, incomingBandwidth, outgoingBandwidth);

            if (this.host == IntPtr.Zero)
            {
                throw new ENetException(0, "Host creation call failed.");
            }

            if (enableCrc)
            {
                NativeMethods.enet_enable_crc(this.host);
            }
        }
Ejemplo n.º 2
0
        public ClientHost(uint peerLimit         = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
                          uint channelLimit      = 0, uint incomingBandwidth = 0,
                          uint outgoingBandwidth = 0, bool enableCrc         = true)
        {
            if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException("peerLimit");
            }
            CheckChannelLimit(channelLimit);

            this.host = NativeMethods.enet_host_create(IntPtr.Zero, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth);

            if (this.host == IntPtr.Zero)
            {
                throw new ENetException(0, "Host creation call failed.");
            }

            if (enableCrc)
            {
                this.EnableCrc();
            }
        }