From a6e19e79233d0e035a8446aa2cb0f9c1f8ed1576 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Mon, 12 Jun 2017 18:50:48 -0700 Subject: [PATCH] WebSocket is now connecting --- Ooui/Client.js | 14 +++++++++++++- Ooui/Server.cs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Ooui/Client.js b/Ooui/Client.js index 1868524..5e047d5 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -1,4 +1,16 @@ +// Create WebSocket connection. +const socket = new WebSocket ("ws://localhost:8080", "ooui-1.0"); -alert("Hello"); +console.log("Socket created"); +// Connection opened +socket.addEventListener('open', function (event) { + console.log("Socket opened"); + socket.send('Hello Server!'); +}); + +// Listen for messages +socket.addEventListener('message', function (event) { + console.log('Message from server', event.data); +}); diff --git a/Ooui/Server.cs b/Ooui/Server.cs index 9e25de3..f4f51f2 100644 --- a/Ooui/Server.cs +++ b/Ooui/Server.cs @@ -119,7 +119,7 @@ namespace Ooui { WebSocketContext webSocketContext = null; try { - webSocketContext = await listenerContext.AcceptWebSocketAsync(subProtocol: null).ConfigureAwait (false); + webSocketContext = await listenerContext.AcceptWebSocketAsync(subProtocol: "ooui-1.0").ConfigureAwait (false); Console.WriteLine ("Accepted WebSocket: {0}", webSocketContext); } catch (Exception e) {