Last active
June 12, 2022 15:37
-
-
Save KMurphs/6efcbfe36b2d680f6fd3741796e846b9 to your computer and use it in GitHub Desktop.
Revisions
-
KMurphs revised this gist
Jun 12, 2022 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ function SimpleWebSocket(address) { if(!("WebSocket" in window)) { console.log("WebSocket NOT supported by your Browser!"); return null } @@ -29,5 +29,6 @@ function SimpleWebSocket(address) { const address = "ws://127.0.0.1:8010"; var ws = SimpleWebSocket(address); ws?.send("My awesome message"); ws?.send("My second awesome message"); -
KMurphs revised this gist
Jun 12, 2022 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function SimpleWebSocket(address) { if(!("WebSocket" in window)) { console.log("WebSocket NOT supported by your Browser!"); return null } // Let us open a web socket var ws = new WebSocket(address); ws.onopen = function() { // Web Socket is connected, send data using send() console.log("Socket is opened..."); }; ws.onmessage = function (evt) { var received_msg = evt.data; console.log("Message is received...", received_msg); }; ws.onclose = function() { // websocket is closed. console.log("Connection is closed..."); }; console.log("WebSocket is supported by your Browser!"); return ws; } const address = "ws://127.0.0.1:8010"; var ws = WebSocketTest(address) ws?.send("My awesome message") -
KMurphs revised this gist
Dec 1, 2021 . 1 changed file with 22 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,34 @@ var msg = "My awesome message"; const address = "ws://127.0.0.1:8010"; (function WebSocketTest() { if ("WebSocket" in window) { console.log("WebSocket is supported by your Browser!"); // Let us open a web socket var ws = new WebSocket(address); ws.onopen = function() { // Web Socket is connected, send data using send() ws.send(msg); console.log("Message is sent..."); }; ws.onmessage = function (evt) { var received_msg = evt.data; console.log("Message is received...", received_msg); }; ws.onclose = function() { // websocket is closed. console.log("Connection is closed..."); }; } else { // The browser doesn't support WebSocket console.log("WebSocket NOT supported by your Browser!"); } })() -
KMurphs revised this gist
Dec 1, 2021 . No changes.There are no files selected for viewing
-
KMurphs created this gist
Dec 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ var msg = "My awesomest message"; const address = "ws://127.0.0.1:8010"; (function WebSocketTest() { if ("WebSocket" in window) { console.log("WebSocket is supported by your Browser!"); // Let us open a web socket var ws = new WebSocket(address); ws.onopen = function() { // Web Socket is connected, send data using send() ws.send(msg); console.log("Message is sent..."); }; ws.onmessage = function (evt) { var received_msg = evt.data; console.log("Message is received...", received_msg); }; ws.onclose = function() { // websocket is closed. console.log("Connection is closed..."); }; } else { // The browser doesn't support WebSocket console.log("WebSocket NOT supported by your Browser!"); } })()