Beispiel #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();
        }
        static async Task Main(string[] args)
        {
            Console.WriteLine("Here");
            int p2p_port = 50216;
            Uri _uri     = new Uri($@"ws://localhost:{p2p_port}/");
            WebSocketConnection socketConnection = await WebSocketClient.Connect(_uri, LogToConsole);

            socketConnection.onMessage = LogToConsole;
            API api = new API(socketConnection);
            //api.GetMenuFromServer();
            await socketConnection.SendAsync("GET_MENU_REQ");

            while (true)
            {
                //
            }
        }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            var server = new WebSocketEchoServer(8888);

            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromMinutes(1));

            Task.Run(() => server.Start(cts.Token), cts.Token);

            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);

            await client.Connect();

            Console.Read();
        }