Example #1
0
        public UPoller(string hostName, ushort port)
        {
            this.acceptor = new USocket(IntPtr.Zero, this);
            UAddress    address       = new UAddress(hostName, port);
            ENetAddress nativeAddress = address.Struct;

            this.host = NativeMethods.ENetHostCreate(ref nativeAddress,
                                                     NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);

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

            NativeMethods.ENetHostCompressWithRangeCoder(this.host);
        }
Example #2
0
        public Task <bool> ConnectAsync(string hostName, ushort port)
        {
            var         tcs           = new TaskCompletionSource <bool>();
            UAddress    address       = new UAddress(hostName, port);
            ENetAddress nativeAddress = address.Struct;

            this.peerPtr = NativeMethods.ENetHostConnect(this.poller.Host, ref nativeAddress,
                                                         NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, 0);
            if (this.PeerPtr == IntPtr.Zero)
            {
                throw new UException("host connect call failed.");
            }
            this.poller.USocketManager.Add(this.PeerPtr, this);
            this.Connected = eEvent =>
            {
                if (eEvent.Type == EventType.Disconnect)
                {
                    tcs.TrySetException(new UException("socket disconnected in connect"));
                }
                tcs.TrySetResult(true);
            };
            return(tcs.Task);
        }
Example #3
0
		internal static extern IntPtr ENetHostConnect(
				IntPtr host, ref ENetAddress address, uint channelCount, uint data);
Example #4
0
		internal static extern IntPtr ENetHostCreate(
				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
				uint outgoingBandwidth);
Example #5
0
		internal static extern int ENetAddressGetHostIp(
				ref ENetAddress address, StringBuilder hostIp, uint ipLength);
Example #6
0
		internal static extern int ENetAddressGetHost(
				ref ENetAddress address, StringBuilder hostName, uint nameLength);
Example #7
0
		internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);