Beispiel #1
0
        public virtual void Server_SendToOneClient_ClientReceivesData()
        {
            var ctx = CreateContext();

            Server.StartServer(ctx);
            foreach (var client in Clients)
            {
                client.Connect(ctx);
            }

            Wait(() =>
            {
                Server.UpdateServer();
                foreach (var client in Clients)
                {
                    client.UpdateClient();
                }

                return(Clients.All(c => c.IsConnected));
            }, 250);

            string     data   = Guid.NewGuid().ToString();
            TestPacket packet = CreateTestPacket(data);
            DataBuffer buffer = new DataBuffer();

            packet.WriteTo(buffer);


            int received = 0;

            foreach (var cl in Clients)
            {
                cl.DataReceived += (s, a) => {
                    var inc = a.Data;
                    Assert.IsNotNull(inc);
                    TestPacket result = new TestPacket();
                    result.ReadFrom(inc);
                    Assert.AreEqual(result.Data, data);
                    received++;
                }
            }
            ;

            Server.SendMessage(Server.GetClientKeys().First(), buffer);
            Wait(() =>
            {
                Server.UpdateServer();
                foreach (var client in Clients)
                {
                    client.UpdateClient();
                }

                return(received == 1);
            }, 250);

            Assert.AreEqual(received, 1);
        }
Beispiel #2
0
        public virtual void Server_SendToClient_ClientReceivesData()
        {
            var client = Clients.First();
            var ctx    = CreateContext();

            Server.StartServer(ctx);
            client.Connect(ctx);

            Wait(() =>
            {
                Server.UpdateServer();
                client.UpdateClient();
                return(client.IsConnected);
            }, 250);

            string     data   = Guid.NewGuid().ToString();
            TestPacket packet = CreateTestPacket(data);
            DataBuffer buffer = new DataBuffer();

            packet.WriteTo(buffer);

            DataBuffer inc = null;

            client.DataReceived += (s, a) => {
                inc = a.Data;
            };

            foreach (var key in Server.GetClientKeys())
            {
                Server.SendMessage(key, buffer);
            }

            Wait(() =>
            {
                Server.UpdateServer();
                client.UpdateClient();

                return(inc != null);
            }, 250);

            Assert.IsNotNull(inc);
            TestPacket result = new TestPacket();

            result.ReadFrom(inc);

            Assert.AreEqual(result.Data, data);
        }
Beispiel #3
0
        public virtual void Server_SendToAllClients_ClientReceivesData()
        {
            var ctx = CreateContext();

            Server.StartServer(ctx);
            for (int i = 0; i < Clients.Count; i++)
            {
                var client = Clients[i];
                client.Connect(ctx);
            }

            Wait(() =>
            {
                Server.UpdateServer();
                foreach (var client in Clients)
                {
                    client.UpdateClient();
                }

                return(Server.GetClientKeys().Count() == Clients.Count);
            }, 250);

            string     data   = Guid.NewGuid().ToString();
            TestPacket packet = CreateTestPacket(data);
            DataBuffer buffer = new DataBuffer();

            packet.WriteTo(buffer);

            int received = 0;

            foreach (var cl in Clients)
            {
                cl.DataReceived += (s, a) => {
                    var inc = a.Data;

                    Assert.IsNotNull(inc);
                    TestPacket result = new TestPacket();
                    result.ReadFrom(inc);
                    Assert.AreEqual(result.Data, data);
                    received++;
                }
            }
            ;

            foreach (var key in Server.GetClientKeys())
            {
                Server.SendMessage(key, buffer);
            }

            Wait(() =>
            {
                Server.UpdateServer();
                foreach (var client in Clients)
                {
                    client.UpdateClient();
                }

                return(received == Clients.Count);
            }, 250);

            Assert.AreEqual(received, Clients.Count);
        }