Пример #1
0
        public async Task CanReceiveDataUsingTasksToHostedEchoServer()
        {
            string request = "GET /index.html HTTP/1.1\r\nHost: www.example.com\r\n\r\n";

            byte[] input  = Encoding.ASCII.GetBytes(request);
            byte[] output = new byte[input.Length];

            using (CompletionThread worker = new CompletionThread())
            {
                SocketFactory factory = new SocketFactory(worker);
                TcpSocket     socket  = factory.Tcp();

                using (EchoServer server = new EchoServer(factory))
                {
                    socket.Bind();
                    worker.Start();
                    server.Start();

                    await socket.Connect(server.Endpoint);

                    await socket.Send(input);

                    await socket.Receive(output);

                    Assert.That(input, Is.EqualTo(output));
                }
            }
        }
Пример #2
0
        public async Task CanHandleRequest()
        {
            using (CompletionThread worker = new CompletionThread())
            {
                SocketFactory factory = new SocketFactory(worker);
                EchoClient    client  = new EchoClient(factory);

                using (EchoServer server = new EchoServer(factory))
                {
                    worker.Start();
                    server.Start();

                    string payload  = "abc";
                    string response = await client.Send(server.Endpoint, payload);

                    Assert.That(response, Is.EqualTo(payload));
                }
            }
        }