Inheritance: IServer
示例#1
0
        static void Main(string[] args)
        {
            IServer server = new TcpServer();
            IPort port = server.Bind(8181);
            port.AddHandler(new ServerHandler());

            IPipe pipe = new TcpPipe("localhost", 8181);
            pipe.AddHandler(new ClientHandler());

            String message;
            do
            {
                Console.Write("Message to send: ");
                message = Console.ReadLine();
                if (message.Length > 0)
                {
                    pipe.Send(message);
                }
            }
            while(message.Length > 0);
        }
示例#2
0
        public void TestSimpleMessageExchange()
        {
            HandlerMock clientHandler = new HandlerMock();
            HandlerMock serverHandler = new HandlerMock();

            IServer server = new TcpServer();
            IPort port = server.Bind(8989);
            port.AddHandler(serverHandler);

            IPipe pipe = new TcpPipe("localhost", 8989);
            pipe.AddHandler(clientHandler);

            MyMessage message = new MyMessage();
            IDelivery delivery = pipe.Send(message);
            delivery.WaitFor(2000);
            Assert.IsTrue(delivery.Done);
            Assert.IsTrue(delivery.Success);

            serverHandler.WaitForMessage(2000);
            Assert.AreEqual(message, serverHandler.LastMessage);
        }