Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            const int NumClients = 1;

            const int Port     = 16738;
            var       endPoint = new IPEndPoint(IPAddress.Loopback, Port);

            var s = new MyServer();

            s.Listen(endPoint);

            s.Received += S_Received;

            async Task runClient()
            {
                var c = await MyClient.CreateAsync(endPoint);

                c.Received += C_Received;

                for (int i = 0; i < 10; i++)
                {
                    await Task.Delay(10);

                    await c.SendAsync((byte)i, new byte[i]);
                }
            }

            Task.WhenAll(Enumerable.Range(0, NumClients).Select(_ => runClient()));

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public MyConnection(MyServer server, IDuplexPipe pipe)
        {
            _server = server;
            _pipe   = pipe;

            _cts      = new CancellationTokenSource();
            _readLoop = ReadLoop(_cts.Token);
        }