public void SendNatIntroduceRequest(IPEndPoint masterServerEndPoint, string additionalInfo) { //prepare outgoing data NetDataWriter dw = new NetDataWriter(); string networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv4); if (string.IsNullOrEmpty(networkIp)) { networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv6); } IPEndPoint localEndPoint = NetUtils.MakeEndPoint(networkIp, _socket.LocalPort); dw.Put((byte)PacketProperty.NatIntroductionRequest); dw.Put(localEndPoint); dw.Put(additionalInfo, MaxTokenLength); //prepare packet int errorCode = 0; _socket.SendTo(dw.Data, 0, dw.Length, masterServerEndPoint, ref errorCode); }
/// <summary> /// Connect to remote host /// </summary> /// <param name="address">Server IP or hostname</param> /// <param name="port">Server Port</param> /// <param name="connectionData">Additional data for remote peer</param> /// <returns>Null if connections limit reached, New NetPeer if new connection, Old NetPeer if already connected</returns> /// <exception cref="InvalidOperationException">Manager is not running. Call <see cref="Start()"/></exception> public NetPeer Connect(string address, int port, NetDataWriter connectionData) { var ep = NetUtils.MakeEndPoint(address, port); return(Connect(ep, connectionData)); }
/// <summary> /// Connect to remote host /// </summary> /// <param name="address">Server IP or hostname</param> /// <param name="port">Server Port</param> /// <param name="key">Connection key</param> /// <returns>Null if connections limit reached, New NetPeer if new connection, Old NetPeer if already connected</returns> /// <exception cref="InvalidOperationException">Manager is not running. Call <see cref="Start()"/></exception> public NetPeer Connect(string address, int port, string key) { var ep = NetUtils.MakeEndPoint(address, port); return(Connect(ep, key)); }