//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);
        });
    }
예제 #2
0
 private void OnReliableTransmitCallback(byte[] payload, int payloadSize)
 {
     if (_client.Status == NetcodeClientStatus.Connected)
     {
         _client.Send(payload, payloadSize);
     }
 }
    IEnumerator doStuff()
    {
        int sent = 0;

        while (true)
        {
            if (client.Status == NetcodeClientStatus.Connected)
            {
                // send a packet
                var packetStr = "pkt " + sent + "! " + System.DateTime.Now.ToString();
                sent++;
                SentText.text = "Sent: " + sent;

                var packetBuffer = System.Text.Encoding.ASCII.GetBytes(packetStr);

                client.Send(packetBuffer);
            }

            yield return(new WaitForSeconds(0.25f));
        }
    }