Ejemplo n.º 1
0
        public void ClientToServer()
        {
            EasyNetwork.Server server = new EasyNetwork.Server("tcp://*:1982");
            EasyNetwork.Client clientOne = new EasyNetwork.Client("tcp://localhost:1982");
            EasyNetwork.Client clientTwo = new EasyNetwork.Client("tcp://localhost:1982");
            MyTestObject obj = new MyTestObject();
            obj.Value = 3.14159f;
            obj.Text = "Hello World!";

            OtherTestObject obj2 = new OtherTestObject();
            obj2.Value = 1234;
            obj2.Text = "Hello World Again!";

            server.Start();
            clientOne.Start();
            clientTwo.Start();

            clientOne.Send<MyTestObject>(obj);
            clientTwo.Send<OtherTestObject>(obj2);

            // Generically receive object at server from first client
            Object receivedObject = null;
            while (receivedObject == null)
            {
                Guid firstId;
                receivedObject = server.Receive(out firstId);

                if (receivedObject is MyTestObject)
                {
                    MyTestObject actualObjectOne = receivedObject as MyTestObject;
                    Assert.AreEqual(clientOne.Id, firstId);
                    Assert.AreEqual(obj.Value, actualObjectOne.Value);
                    Assert.AreEqual(obj.Text, actualObjectOne.Text);
                }

                Thread.Sleep(100);
            }

            // Generically receive object at server from second client
            receivedObject = null;
            while (receivedObject == null)
            {
                Guid secondId;
                receivedObject = server.Receive(out secondId);

                if (receivedObject is OtherTestObject)
                {
                    OtherTestObject actualObjectTwo = receivedObject as OtherTestObject;
                    Assert.AreEqual(clientTwo.Id, secondId);
                    Assert.AreEqual(obj2.Value, actualObjectTwo.Value);
                    Assert.AreEqual(obj2.Text, actualObjectTwo.Text);
                }

                Thread.Sleep(100);
            }

            server.Stop();
            clientOne.Stop();
            clientTwo.Stop();
        }
Ejemplo n.º 2
0
        public void ServerResponses()
        {
            EasyNetwork.Server server    = new EasyNetwork.Server("tcp://*:1982");
            EasyNetwork.Client clientOne = new EasyNetwork.Client("tcp://localhost:1982");
            EasyNetwork.Client clientTwo = new EasyNetwork.Client("tcp://localhost:1982");

            server.Start();
            clientOne.Start();
            clientTwo.Start();

            // Build and send a message to the server
            MyTestObject clientOneMessage = new MyTestObject();

            clientOneMessage.Value = 3.14159f;
            clientOneMessage.Text  = "Hello Server!";
            clientOne.Send <MyTestObject>(clientOneMessage);

            // Server receives, handles, and responds to message
            Object receivedObj = null;

            while (receivedObj == null)
            {
                Guid receivedId;
                receivedObj = server.Receive(out receivedId);

                if (receivedObj is MyTestObject)
                {
                    MyTestObject receivedMessage = receivedObj as MyTestObject;
                    MyTestObject responseMessage = new MyTestObject();
                    responseMessage.Value = receivedMessage.Value * 2;
                    responseMessage.Text  = "Howdy client!";

                    server.Send <MyTestObject>(receivedMessage, receivedId);
                }

                Thread.Sleep(100);
            }

            Thread.Sleep(1000);

            // Make sure the second client didn't receive anything
            Object clientTwoReceived = clientTwo.Receive();

            Assert.IsNull(clientTwoReceived);

            // The clientOne should have received the message destined for it
            Object clientReceived = clientOne.Receive();

            Assert.IsNotNull(clientReceived);
            Assert.IsTrue(clientReceived is MyTestObject);

            server.Stop();
            clientOne.Stop();
            clientTwo.Stop();
        }
Ejemplo n.º 3
0
        public void ClientToServer()
        {
            EasyNetwork.Server server    = new EasyNetwork.Server("tcp://*:1982");
            EasyNetwork.Client clientOne = new EasyNetwork.Client("tcp://localhost:1982");
            EasyNetwork.Client clientTwo = new EasyNetwork.Client("tcp://localhost:1982");
            MyTestObject       obj       = new MyTestObject();

            obj.Value = 3.14159f;
            obj.Text  = "Hello World!";

            OtherTestObject obj2 = new OtherTestObject();

            obj2.Value = 1234;
            obj2.Text  = "Hello World Again!";

            server.Start();
            clientOne.Start();
            clientTwo.Start();

            clientOne.Send <MyTestObject>(obj);
            clientTwo.Send <OtherTestObject>(obj2);

            // Generically receive object at server from first client
            Object receivedObject = null;

            while (receivedObject == null)
            {
                Guid firstId;
                receivedObject = server.Receive(out firstId);

                if (receivedObject is MyTestObject)
                {
                    MyTestObject actualObjectOne = receivedObject as MyTestObject;
                    Assert.AreEqual(clientOne.Id, firstId);
                    Assert.AreEqual(obj.Value, actualObjectOne.Value);
                    Assert.AreEqual(obj.Text, actualObjectOne.Text);
                }

                Thread.Sleep(100);
            }

            // Generically receive object at server from second client
            receivedObject = null;
            while (receivedObject == null)
            {
                Guid secondId;
                receivedObject = server.Receive(out secondId);

                if (receivedObject is OtherTestObject)
                {
                    OtherTestObject actualObjectTwo = receivedObject as OtherTestObject;
                    Assert.AreEqual(clientTwo.Id, secondId);
                    Assert.AreEqual(obj2.Value, actualObjectTwo.Value);
                    Assert.AreEqual(obj2.Text, actualObjectTwo.Text);
                }

                Thread.Sleep(100);
            }

            server.Stop();
            clientOne.Stop();
            clientTwo.Stop();
        }
Ejemplo n.º 4
0
        public void ServerResponses()
        {
            EasyNetwork.Server server = new EasyNetwork.Server("tcp://*:1982");
            EasyNetwork.Client clientOne = new EasyNetwork.Client("tcp://localhost:1982");
            EasyNetwork.Client clientTwo = new EasyNetwork.Client("tcp://localhost:1982");

            server.Start();
            clientOne.Start();
            clientTwo.Start();

            // Build and send a message to the server
            MyTestObject clientOneMessage = new MyTestObject();
            clientOneMessage.Value = 3.14159f;
            clientOneMessage.Text = "Hello Server!";
            clientOne.Send<MyTestObject>(clientOneMessage);

            // Server receives, handles, and responds to message
            Object receivedObj = null;
            while (receivedObj == null)
            {
                Guid receivedId;
                receivedObj = server.Receive(out receivedId);

                if (receivedObj is MyTestObject)
                {
                    MyTestObject receivedMessage = receivedObj as MyTestObject;
                    MyTestObject responseMessage = new MyTestObject();
                    responseMessage.Value = receivedMessage.Value * 2;
                    responseMessage.Text = "Howdy client!";

                    server.Send<MyTestObject>(receivedMessage, receivedId);
                }

                Thread.Sleep(100);
            }

            Thread.Sleep(1000);

            // Make sure the second client didn't receive anything
            Object clientTwoReceived = clientTwo.Receive();
            Assert.IsNull(clientTwoReceived);

            // The clientOne should have received the message destined for it
            Object clientReceived = clientOne.Receive();
            Assert.IsNotNull(clientReceived);
            Assert.IsTrue(clientReceived is MyTestObject);

            server.Stop();
            clientOne.Stop();
            clientTwo.Stop();
        }