示例#1
0
        public void SocketConnect()
        {
            const int port = 5050;
            const int clientCount = 10;
            var listener = SocketEvents.GetTcpStreamSockets(port);
            var countdown = new CountdownEvent(clientCount);
            try
            {
                var tcs = new TaskCompletionSource<object>();
                int count = 0;
                listener.Subscribe(s =>
                {
                    count++;
                    countdown.Signal();
                    s.Close();
                },
                tcs.SetException,
                () => tcs.TrySetResult(null));

                for (int i = 0; i < clientCount; i++)
                {
                    SocketTestUtility.Connect(port);
                }

                countdown.WaitEx();
                Assert.IsTrue(count == clientCount);
            }
            finally
            {
                listener.Dispose();
            }
        }