Created
October 7, 2020 15:18
-
-
Save wayneseymour/1a5146093aedc8d09881c939393eaf4d to your computer and use it in GitHub Desktop.
SImple echo spike
This file contains 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 characters
// Start the connection to the WebSocket server at echo.websocket.org | |
ws = new WebSocket("ws://echo.websocket.org/"); | |
// Register event listeners for the open, close, and message events | |
ws.onopen = () => { | |
console.log("WebSocket ready!"); | |
console.log('yo') | |
ws.send('yo') | |
}; | |
ws.onmessage = (message) => { | |
// Log the message we recieve: | |
console.log("Received data:", message.data); | |
// Close the websocket after receiving the "exit" message (the last line) | |
if(message.data == "exit") ws.close(); | |
}; | |
ws.onclose = () => console.log("WebSocket closed!"); | |
ws.onerror = (err) => console.log("WebSocket error:", err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment