public ListenMessagesFromClient(Sandbox sandbox, int port) { Sandbox = sandbox; Listener = new UdpMessageListener(port); Listener.Listen(MessageReceived); Sandbox.OnWorldUpdateAfterCollisions.Subscribe(AfterWorldUpdate); }
public void ShouldReceiveMessagesFromMultipleSources() { var listenerPort = 20002; var expectedMessages = new string[] { "msg 1", "msg 2" }; var listener = new UdpMessageListener(listenerPort); var count = 0; listener.Listen((actualMessage, address) => { count++; Assert.IsTrue(expectedMessages.Contains(actualMessage)); if (count >= 2) { AsyncAssert.Done(); } }); var writer1 = new UdpMessageSender(); var writer2 = new UdpMessageSender(); writer1.Send(expectedMessages[0], "localhost", listenerPort); writer2.Send(expectedMessages[1], "localhost", listenerPort); AsyncAssert.Wait(); writer1.Dispose(); writer2.Dispose(); listener.Dispose(); }
public ListenMessagesFromServer(Sandbox sandbox, int port, string playerName) { Sandbox = sandbox; TempPosition = new Position(0, 0); Listener = new UdpMessageListener(port); Listener.Listen(MessageReceived); PlayerName = playerName; Sandbox.OnWorldUpdateAfterCollisions.Subscribe(WorldUpdate); }
public IpDiscover(Action <string> onNewIpDiscovered) { IpsFound = new List <string>(); OnNewIpDiscovered = onNewIpDiscovered; port = 47777; myIp = NetworkHelper.GetLocalIPAddress(); broadcastIp = NetworkHelper.GetBroadcastAddress( IPAddress.Parse(myIp), IPAddress.Parse("255.255.255.0")).ToString(); listener = new UdpMessageListener(port); sender = new UdpMessageSender(); listener.Listen(OnMessageReceived); var operation = new ParameterizedThreadStart(Broadcast); broadcastLoop = new Thread(operation, 1024 * 1024); broadcastLoop.Start(); }
public void ShouldReceiveAtLeastMessage() { var listenerPort = 20000; var expectedMessage = "Opa! excelente~"; var listener = new UdpMessageListener(listenerPort); listener.Listen((actualMessage, address) => { Assert.AreEqual(expectedMessage, actualMessage); AsyncAssert.Done(); }); var writer = new UdpMessageSender(); writer.Send(expectedMessage, "localhost", listenerPort); AsyncAssert.Wait(); writer.Dispose(); listener.Dispose(); }