protected async override Task Inner_Connect(EndPoint Address)
 {
     Socket = new WebAssembly.Net.WebSockets.ClientWebSocket();
     await Socket.ConnectAsync(
         new Uri("ws://" + Address.IpAddress + ":" + Address.Port.ToString() + "/Client/"),
         CancellationToken.None);
 }
        public RemoteRepository()
        {
            ClientWebSocket cws = new ClientWebSocket();

            cws.ConnectAsync(new Uri("ws://127.0.0.1:9301/ws"), CancellationToken.None);
            _dataProvider = async expression =>
            {
                IEnumerable <DynamicObject> result = null;
                try
                {
                    // Console.WriteLine("remote repo:sending to ws://127.0.0.1:9301/ws");
                    // string json = Newtonsoft.Json.JsonConvert.SerializeObject(expression, serializerSettings);
                    // Console.WriteLine("serializiation:" + json);
                    // Console.WriteLine("pre:");
                    // await cws.Sendas(json);
                    // var reply = await cws.ReceiveHostCloseWebSocket();
                    // System.Threading.Thread.Sleep(1000);
                    // reply = await cws.WebSocketRecvText();
                    // Console.WriteLine($"reply: {reply}");
                    Console.WriteLine("inthread!!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(result);
            };
        }
Beispiel #3
0
        static async void TestWS()
        {
            Console.WriteLine("ws call....");
            ClientWebSocket cws = new ClientWebSocket();
            await cws.ConnectAsync(new Uri("ws://127.0.0.1:9301/ws"), CancellationToken.None);

            await cws.SendAsync(new ArraySegment <byte> (Encoding.UTF8.GetBytes("{test}")), WebSocketMessageType.Text, true, CancellationToken.None);

            var buffer = new ArraySegment <byte> (new byte [4096]);
            var result = await cws.ReceiveAsync(buffer, CancellationToken.None);

            Console.WriteLine("....ws call -> " + Encoding.UTF8.GetString(buffer));
        }
Beispiel #4
0
        public async static void sendrecv(string json)
        {
            Console.WriteLine("ws call.... passing" + json);

            ClientWebSocket cws = new ClientWebSocket();

            {
                var buffer = new ArraySegment <byte> (new byte [4096]);
                await cws.ConnectAsync(new Uri("ws://127.0.0.1:9301/ws"), CancellationToken.None);

                await cws.SendAsync(new ArraySegment <byte> (Encoding.UTF8.GetBytes(json)), WebSocketMessageType.Text, true, CancellationToken.None);

                await cws.ReceiveAsync(buffer, CancellationToken.None);

                _result = Encoding.UTF8.GetString(buffer);
            }

            Console.WriteLine("....ws call");
        }
Beispiel #5
0
        static void TestThread()
        {
            Console.WriteLine("Thread Test ....");
            try
            {
                var task1 = new Thread(() =>
                {
                    Console.WriteLine("IN BTNCLICK THREAD!");
                    ClientWebSocket cws = new ClientWebSocket();
                    cws.ConnectAsync(new Uri("ws://127.0.0.1:9301/ws"), CancellationToken.None);
                });

                task1.Join();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("....Thread Test");
        }
Beispiel #6
0
        private async Task ConnectWebSocket(Uri server, string protocols)
        {
            _cancellation = new CancellationTokenSource();

            checkWebSocket(server, protocols);


            using (var cts2 = new CancellationTokenSource(4000)) {
                try {
                    Task  taskConnect = cws.ConnectAsync(server, cts2.Token);
                    await taskConnect;
                } catch (Exception exc) {
                    await UpdateMessageArea($"ConnectWebSocket connect exception: {cws.CloseStatus} - {cws.CloseStatusDescription} / {exc.Message}", true);
                    await UpdateMessageArea($"ConnectWebSocket connect inner exception: {cws.CloseStatus} - {cws.CloseStatusDescription} / {exc.InnerException?.Message}", true);
                }
            }

            if (cws.State == WebSocketState.Open)
            {
                RunReceiveLoop();
            }
        }