Example #1
0
        /// <summary>
        /// Request to connect to a remote host at specified address and port.
        /// </summary>
        public void Connect(string address, ushort port)
        {
            ENet.Address remoteAddr = new ENet.Address();
            remoteAddr.Port = port;
            ENet.AddressSetHost(ref remoteAddr, Encoding.ASCII.GetBytes(address));

            ENet.Connect(host, ref remoteAddr, (IntPtr)config.DefaultChannelAmount);
        }
Example #2
0
        /// <summary>
        /// Request to connect to a remote host at specified address and port.
        /// </summary>
        public void Connect(IPEndPoint ipEndPoint)
        {
            // Check if this technique actually works in anycase. Stay noted, this is prevent the obsolete IPv4 feature in .NET IPAdress
            // However, we cut away the IPv6 section - This is because ENet does not support IPv6.
            // uint value = BitConverter.ToUInt32(ipEndPoint.Address.GetAddressBytes(), 0);
            ENet.Address remoteAddr = new ENet.Address()
            {
                Host = (uint)ipEndPoint.Address.Address,
                Port = remoteAddr.Port = (ushort)ipEndPoint.Port,
            };

            ENet.Connect(host, ref remoteAddr, (IntPtr)config.DefaultChannelAmount);
        }
Example #3
0
        internal void NATPunching(IPEndPoint addr)
        {
            ENet.Address address = new ENet.Address();
            address.Port = (ushort)config.Port;
            string strAddr = addr.Address.ToString();

            if (ENet.AddressSetHost(ref address, Encoding.ASCII.GetBytes(strAddr)) != 0)
            {
                Debug.Log(config.Name, " Failed to resolve host name");
            }

            Debug.Log(config.Name, " Punching: ", addr.Address.ToString(), " : ", address.Port.ToString());

            ENet.Connect(host, ref address, (IntPtr)config.DefaultChannelAmount);
        }
Example #4
0
        private void Initialize()
        {
            ENet.Initialize();

            InitializePools();
            InitializeQueues(config.IncomingBufferSize);

            connections = new RemoteConnection[config.MaxConnections];

            if (config.AllowConnectors)
            {
                ENet.Address address = new ENet.Address();
                address.Port = config.Port;


                ENet.AddressSetHost(ref address, config.LocalAddress);
                host = ENet.CreateHost(ref address, (IntPtr)config.MaxConnections, (IntPtr)config.MaxConnections, config.IncomingBandwidth, config.OutgoingBandwidth, config.AppIdentification);
            }
            else
            {
                host = ENet.CreateHost(null, (IntPtr)config.MaxConnections, (IntPtr)config.MaxConnections, config.IncomingBandwidth, config.OutgoingBandwidth, config.AppIdentification);
            }

            if (host == null)
            {
                Debug.Error(config.Name, ": Failed to create host");
                return;
            }

            IncomingMessage readyEvent = GetIncomingMessage();

            readyEvent.Event = EventMessage.NetworkReady;
            IncomingEnqueue(readyEvent);

            isRunning   = true;
            isConfigSet = false;
        }