//Connection... public void connectToServer() { localClientID = ulong.Parse(idClientText.text); serverIP = ipServerText.text; ipEndPoint = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(serverIP), serverPORT) }; Debug.LogError("Generating token on client..."); TokenFactory factory = new TokenFactory(ProtocolID, privateKey); byte[] connectToken = factory.GenerateConnectToken(ipEndPoint,300, 100, 10UL, localClientID, new byte[256]); client.Connect(connectToken, () => { Debug.LogError("Client connected to server !!!"); StartCoroutine(updateStatus()); client.AddPayloadListener(RecievePacket); reliableEndpoint.ReceiveCallback = (message, messageSize) => { RecieveMessage(message, messageSize); }; reliableEndpoint.TransmitCallback = (payload, size) => { client.Send(payload, size); }; isConnected = true; }, (error) => { Debug.LogError("FAILED CONNECTION: " + error); }); }
IEnumerator connectToServer() { logLine("Obtaining connect token..."); UnityWebRequest webRequest = UnityWebRequest.Get(TokenServer); yield return(webRequest.Send()); if (webRequest.isNetworkError) { logLine("Failed to obtain connect token: " + webRequest.error); yield break; } byte[] connectToken = System.Convert.FromBase64String(webRequest.downloadHandler.text); client.Connect(connectToken, () => { logLine("Connected to netcode.io server!"); // add listener for network messages client.AddPayloadListener(ReceivePacket); // do stuff StartCoroutine(updateStatus()); StartCoroutine(doStuff()); }, (err) => { logLine("Failed to connect: " + err); }); }
private void ClientConnect(NetcodeClient client) { var token = new byte[32]; client.Connect(token, ClientConnectSucceedCallback, ClientConnectFailedCallback); }