Example #1
0
 protected void SendToEndpoints(Action <TeleportWriter> serializer, byte channelId = 0, params EndPoint[] endpoints)
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new TeleportWriter(stream))
         {
             serializer(writer);
         }
         _transport.Send(stream.ToArray(), channelId, endpoints);
     }
 }
Example #2
0
        private IEnumerator Start()
        {
            var   port         = 5006;
            float testDuration = 30;

            _clientDataSeq     = 0;
            _serverDataSeq     = 0;
            _clientMissingSeqs = new List <int>();
            _serverMissingSeqs = new List <int>();
            Debug.Log("Starting test in 3 seconds...");
            yield return(new WaitForSeconds(3));

            var server = new TeleportUdpTransport(() => new TeleportPacketBuffer(), () => new SequencedTeleportChannel(new SimpleTeleportChannel()));
            var client = new TeleportUdpTransport(() => new TeleportPacketBuffer(), () => new SequencedTeleportChannel(new SimpleTeleportChannel()));

            server.StartListener(port);
            client.StartClient("127.0.0.1", port);
            Debug.Log("Waiting for client and server to start...");
            while (!client.ThreadStarted || !server.ThreadStarted)
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(3));

            client.Send(new byte[] { 0, 0, 0, 0 }); // Say hello so server will recognize us
            bool didServerGetHello = false;

            while (!didServerGetHello)
            {
                server.ProcessIncoming((e, r) => { didServerGetHello = true; });
                yield return(null);
            }
            Debug.Log("Server got hello from client");
            yield return(new WaitForSeconds(1));

            while (testDuration > 0)
            {
                for (int i = 0; i < 20; i++)
                {
                    client.Send(SerializeClient);
                }
                for (int i = 0; i < 20; i++)
                {
                    server.Send(SerializeServer);
                }
                server.ProcessIncoming(DeserializeServer);
                client.ProcessIncoming(DeserializeClient);
                testDuration -= Time.deltaTime;
                yield return(null);
            }
            yield return(new WaitForSeconds(10));

            server.StopListener();
            client.StopClient();

            for (int i = 0; i < _serverMissingSeqs.Count; i++)
            {
                Debug.LogError("Missing sequence never got to server: " + i);
            }

            for (int i = 0; i < _clientMissingSeqs.Count; i++)
            {
                Debug.LogError("Missing sequence never got to client: " + i);
            }

            if (_clientMissingSeqs.Count == 0 && _serverMissingSeqs.Count == 0)
            {
                Debug.Log("All passed!");
            }
        }