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); }
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); }
internal static extern IntPtr ENetHostConnect( IntPtr host, ref ENetAddress address, uint channelCount, uint data);
internal static extern IntPtr ENetHostCreate( ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
internal static extern int ENetAddressGetHostIp( ref ENetAddress address, StringBuilder hostIp, uint ipLength);
internal static extern int ENetAddressGetHost( ref ENetAddress address, StringBuilder hostName, uint nameLength);
internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);