private IEnumerator Start() { float testDuration = 30; var port = 6000; var serverTransport = new TeleportUdpTransport(() => new TeleportPacketBuffer(), () => new SequencedTeleportChannel(new SimpleTeleportChannel())); var clientTransport = new TeleportUdpTransport(() => new TeleportPacketBuffer(), () => new SequencedTeleportChannel(new SimpleTeleportChannel())); var server = new TeleportServerProcessor(serverTransport); var client = new TeleportClientProcessor(clientTransport); server.RegisterMessage <TestMessage>(); client.RegisterMessage <TestMessage>(); server.RegisterMessage <TimedMessageTest>(); client.RegisterMessage <TimedMessageTest>(); Debug.Log("Test will start in 3 seconds"); yield return(new WaitForSeconds(3)); server.Listen(port); client.Connect("localhost", port); Debug.Log("Waiting for client to authenticate..."); while (client.State != TeleportClientProcessor.StateType.Connected) { yield return(null); } Debug.Log("Client authenticated with server!"); Debug.Log("Starting transfer, please wait for results (" + testDuration + " seconds)"); while (testDuration > 0) { for (int i = 0; i < 5; i++) { server.SendToAll(new TimedMessageTest()); server.SendToAll(new TestMessage()); } for (int i = 0; i < 5; i++) { client.SendToServer(new TestMessage()); } testDuration -= Time.deltaTime; yield return(null); } Debug.Log("Stopping client and server..."); yield return(new WaitForSeconds(5)); server.StopListening(); client.Disconnect(); Debug.Log("Test complete! Checking results.."); if (TestStats.ClientMissingSeqs.Count > 0) { Debug.LogError("Client missing " + TestStats.ClientMissingSeqs.Count + " messages"); } else if (TestStats.ClientMissingTimedSeqs.Count > 0) { Debug.LogError("Client missing " + TestStats.ClientMissingTimedSeqs.Count + " timed messages"); } else if (TestStats.ServerMissingSeqs.Count > 0) { Debug.LogError("Client missing " + TestStats.ServerMissingSeqs.Count + " timed messages"); } else { Debug.Log("All passed! Client msgs: " + TestStats.ClientSeq + " Client timed msgs: " + TestStats.ClientTimedSeq + " Server msgs: " + TestStats.ServerSeq); } }
public void SendToAllClients(ITeleportMessage message, byte channelId = 0) { _server.SendToAll(message, channelId); }