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); }; }
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)); }
static ClientWebSocket CreateWebSocket(Uri server, string protocols = "") { var cws = new ClientWebSocket(); if (!string.IsNullOrEmpty(protocols)) { foreach (var p in protocols.Split(';')) { cws.Options.AddSubProtocol(p); } } return(cws); }
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"); }
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"); }
static async void checkWebSocket(Uri server, string protocols = "") { if (cws == null) { await UpdateMessageArea($"Create WebSocket: {server}"); cws = new ClientWebSocket(); if (!string.IsNullOrEmpty(protocols)) { //cws.Options.AddSubProtocol("dumb-increment-protocol"); //cws.Options.AddSubProtocol("dumb-increment-protocol2"); //cws.Options.AddSubProtocol ("echo-protocol"); foreach (var p in protocols.Split(';')) { cws.Options.AddSubProtocol(p); } } } }