Example #1
0
        public static ENetAddress FromEndPoint(IPEndPoint endPoint)
        {
            if (endPoint.AddressFamily != AddressFamily.InterNetwork)
            {
                throw new NotSupportedException(string.Format("Address Family {0} not supported", endPoint.AddressFamily));
            }

            ENetAddress address = new ENetAddress();

#pragma warning disable CS0618 // Type or member is obsolete
            address.Host = (uint)endPoint.Address.Address;
#pragma warning restore CS0618 // Type or member is obsolete
            address.Port = (ushort)endPoint.Port;
            return(address);
        }
Example #2
0
        public ENetPeer Connect(IPEndPoint endPoint, byte channels, uint data)
        {
            CheckDispose();

            if (channels < 1)
            {
                throw new ArgumentOutOfRangeException("channels");
            }

            Native.ENetAddress address = Native.ENetAddress.FromEndPoint(endPoint);
            var native = LibENet.HostConnect(Pointer, &address, (UIntPtr)channels, data);

            if (((IntPtr)native) == IntPtr.Zero)
            {
                throw new Exception("Failed to initiate connection.");
            }

            return(new ENetPeer(this, native));
        }