예제 #1
0
        static async Task Main(string[] args)
        {
            var server = new WebSocketEchoServer(8888);

            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(30));

            var client = new WebSocketClient(new Uri("ws://localhost:8888"));

            client.ConnectionOpened.SelectMany(OnConnectionOpened).Subscribe();
            client.MessageReceived.Subscribe(OnMessageReceived);
            client.ErrorOccured.Subscribe(OnErrorOccured);
            client.ConnectionClosed.Subscribe(OnConnectionClosed);

            var cts2 = new CancellationTokenSource();

            cts2.CancelAfter(TimeSpan.FromSeconds(20));

            await Task.WhenAll(server.Start(cts.Token), client.Connect(cts2.Token));

            await client.DisposeAsync();

            Console.Read();
        }