Exemple #1
0
        private void CastTest(int numCasts)
        {
            byte tick = 0;

            using (UDPServer <ByteArrayCast> UDPServer = new UDPServer <ByteArrayCast>(Port))
            {
                using (UDPClient <ByteArrayCast> udpClient = new UDPClient <ByteArrayCast>(Port))
                {
                    udpClient.Received += UdpClient_Received;
                    UDPServer.AddSubscriber(IPAddress.Loopback);

                    for (int i = 0; i < numCasts; i++)
                    {
                        byte[] data1 = new byte[] { 1, 2, 3, 4 };
                        byte[] data2 = new byte[] { 4, 3, 2, 1 };

                        ByteArrayCast sentCast = new ByteArrayCast(tick, new byte[][] { data1, data2 });
                        UDPServer.Broadcast(sentCast);

                        if (castReceived.WaitOne(5000))
                        {
                            Assert.AreEqual(receivedCast, sentCast);
                        }
                        else
                        {
                            throw new Exception("Receive failure");
                        }

                        tick++;
                    }
                }
            }
        }
Exemple #2
0
    private void BroadcastIPAddress()
    {
        string ip = IPUtils.GetIpAddress();

        Debug.LogFormat("广播消息{0}", ip);
        byte[] buf = Encoding.Default.GetBytes(ip);
        udpServer.Broadcast(buf, udpPort);
    }