/// <summary> /// Connects to a remote asynchronously. /// </summary> /// <param name="ip">The IP address of the server.</param> /// <param name="port">The port of the server.</param> /// <param name="callback">The callback to make when the connection attempt completes.</param> public void ConnectInBackground(IPAddress ip, int port, IPVersion ipVersion, DarkRiftClient.ConnectCompleteHandler callback = null) { enetConnnection = new EnetClientConnection(ip.ToString(), port); Client.ConnectInBackground(enetConnnection, delegate(Exception e) { if (callback != null) { if (invokeFromDispatcher) { Dispatcher.InvokeAsync(() => callback(e)); } else { callback.Invoke(e); } } if (ConnectionState == ConnectionState.Connected) { Debug.Log("Connected to " + ip + " on port " + port + " using " + ipVersion + "."); } else { Debug.Log("Connection failed to " + ip + " on port " + port + " using " + ipVersion + "."); } } ); }
/// <summary> /// Connects to a remote server. /// </summary> /// <param name="ip">The IP address of the server.</param> /// <param name="port">The port of the server.</param> public void Connect(IPAddress ip, int port, IPVersion ipVersion) { enetConnnection = new EnetClientConnection(ip.ToString(), port); client.Connect(enetConnnection); //Client.Connect(ip, port, ipVersion); if (ConnectionState == ConnectionState.Connected) { Debug.Log("Connected to " + ip + " on port " + port + " using " + ipVersion + "."); } else { Debug.Log("Connection failed to " + ip + " on port " + port + " using " + ipVersion + "."); } }