コード例 #1
0
        public void TestSimplePipeClientToServerMultiple()
        {
            string pipeName = "SimplePipeTestPipeCTSM";

            using (ServerTest testServer = new ServerTest(pipeName)) {
                SimplePipeClient client = new SimplePipeClient(pipeName);
                //client.Connect();
                client.Write("Test", true);
                testServer.WaitForClients();
                Assert.IsTrue(0 < testServer.RecievedFromClient);

                client.Write("Test1", true);
                testServer.WaitForClients();
                Assert.IsTrue(1 < testServer.RecievedFromClient);

                client.Write("Test2", true);
                testServer.WaitForClients();
                Assert.IsTrue(1 < testServer.RecievedFromClient);

                client.Write("Test3", true);
                testServer.WaitForClients();
                Assert.IsTrue(1 < testServer.RecievedFromClient);

                // TODO: Actually wait until server has nothing else to read.
                //Thread.Sleep( 2000 );
            }
        }
コード例 #2
0
        public void TestSimplePipeClientServerChat()
        {
            string pipeName        = "SimplePipeTestPipeCSC";
            int    clientReadCount = 0;

            using (ServerTest testServer = new ServerTest(pipeName)) {
                SimplePipeClient client = new SimplePipeClient(pipeName);
                client.OnReadCallback = delegate(string messageIn){
                    if (messageIn.StartsWith("Test"))
                    {
                        clientReadCount += 1;
                    }
                };
                client.Listen();

                client.Write("Test", true);
                testServer.WaitForClients();
                Assert.IsTrue(0 < testServer.RecievedFromClient);

                testServer.Write("Test");
                client.WaitForPeers();
                Assert.IsTrue(0 < clientReadCount);

                client.Write("Test1", true);
                testServer.WaitForClients();
                Assert.IsTrue(1 < testServer.RecievedFromClient);

                testServer.Write("TestA");
                client.WaitForPeers();
                Assert.IsTrue(1 < clientReadCount);

                client.Write("Test2", true);
                testServer.WaitForClients();
                Assert.IsTrue(2 < testServer.RecievedFromClient);

                testServer.Write("TestB");
                client.WaitForPeers();
                Assert.IsTrue(2 < clientReadCount);

                client.Write("Test3", true);
                testServer.WaitForClients();
                Assert.IsTrue(3 < testServer.RecievedFromClient);

                testServer.Write("TestC");
                client.WaitForPeers();
                Assert.IsTrue(3 < clientReadCount);
            }
        }
コード例 #3
0
        public void TestSimplePipeServerToClient()
        {
            string pipeName   = "SimplePipeTestPipeSTC";
            bool   clientRead = false;

            using (ServerTest testServer = new ServerTest(pipeName)) {
                SimplePipeClient client = new SimplePipeClient(pipeName);
                client.OnReadCallback += delegate(string messageIn) { clientRead = true; };
                client.Listen();
                testServer.Write("Test");

                // TODO: Actually wait until server has nothing else to read.
                //Thread.Sleep( 2000 );

                testServer.WaitForClients();
                client.WaitForPeers();

                Assert.IsTrue(clientRead);
            }
        }