Esempio n. 1
0
        public void MultipleClientsSingleThread2()
        {
            EchoServer echoServer = new EchoServer();

            echoServer.Start(new IPEndPoint(IPAddress.Any, 2033));

            List <IPEndPoint> endPoints = new List <IPEndPoint>();
            IPEndPoint        ep        = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2033);

            endPoints.Add(ep);
            List <EchoTestClient> aClients = new List <EchoTestClient>();

            for (int i = 0; i < 10; i++)
            {
                EchoTestClient echoClient = new EchoTestClient(endPoints);
                echoClient.Connect(endPoints[0]);
                aClients.Add(echoClient);
            }

            string strTestData2 = "JjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHh";

            for (int j = 0; j < 10; j++)
            {
                EchoTestClient clientMaster = aClients[j];
                clientMaster.SendData(strTestData2);
                for (int i = 0; i < 10; i++)
                {
                    EchoTestClient echoClient = aClients[i];
                    echoClient.DataReady.WaitOne();
                    Assert.IsTrue(string.Equals(strTestData2, echoClient.ReceivedData));
                }
            }
        }
Esempio n. 2
0
        public void SingleThreadSingleClient()
        {
            EchoServer echoServer = new EchoServer();

            echoServer.Start(new IPEndPoint(IPAddress.Any, 2031));

            List <IPEndPoint> endPoints = new List <IPEndPoint>();
            IPEndPoint        ep        = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2031);

            endPoints.Add(ep);
            EchoTestClient echoClient = new EchoTestClient(endPoints);

            echoClient.Connect(endPoints[0]);
            string strTestData = "1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";

            echoClient.SendData(strTestData);
            echoClient.DataReady.WaitOne();
            Assert.IsTrue(string.Equals(strTestData, echoClient.ReceivedData));
            string strTestData2 = "JjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHh";

            echoClient.SendData(strTestData2);
            echoClient.DataReady.WaitOne();
            Assert.IsTrue(string.Equals(strTestData2, echoClient.ReceivedData));
        }