public void Create(Address?address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) { var version = LENet.Version.Patch420; if (_host != null) { throw new InvalidOperationException("Already created."); } if (peerLimit < 0 || peerLimit > version.MaxPeerID) { throw new ArgumentOutOfRangeException("peerLimit"); } CheckChannelLimit(channelLimit); LENet.Address?nativeAddress = null; if (address is Address addr) { nativeAddress = new LENet.Address(addr.IPv4Host, addr.Port); } try { _host = new LENet.Host(version, nativeAddress, (uint)peerLimit, (uint)channelLimit, incomingBandwidth, outgoingBandwidth); } catch (Exception) { throw new ENetException(0, "Host creation call failed."); } }
public Peer Connect(Address address, int channelLimit, uint data) { CheckCreated(); CheckChannelLimit(channelLimit); var nativeAddress = new LENet.Address(address.IPv4Host, address.Port); try { var peer = new Peer(_host.Connect(nativeAddress, (uint)channelLimit)); if (peer.NativeData == null) { throw new ENetException(0, "Host connect call failed."); } return(peer); } catch (Exception) { throw new ENetException(0, "Host connect call failed."); } }