Exemplo n.º 1
0
        public EService(
            string hostName, ushort port, uint peerLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
            uint channelLimit = 0, uint incomingBandwidth = 0, uint outgoingBandwidth = 0)
        {
            if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException(string.Format("peerLimit: {0}", peerLimit));
            }

            if (channelLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
            {
                throw new ArgumentOutOfRangeException(string.Format("channelLimit: {0}", channelLimit));
            }

            var address = new Address {
                HostName = hostName, Port = port
            };
            ENetAddress nativeAddress = address.Struct;

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

            if (this.host == IntPtr.Zero)
            {
                throw new EException("Host creation call failed.");
            }
        }
Exemplo n.º 2
0
        public EService(
            uint peerLimit         = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, uint channelLimit = 0,
            uint incomingBandwidth = 0, uint outgoingBandwidth = 0)
        {
            if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
            {
                throw new ArgumentOutOfRangeException(string.Format("peerLimit: {0}", peerLimit));
            }

            if (channelLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
            {
                throw new ArgumentOutOfRangeException(string.Format("channelLimit: {0}", channelLimit));
            }

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

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