Created
November 16, 2018 14:45
-
-
Save Srushtika/1972f98465e18b98b8124ce5bf25932e to your computer and use it in GitHub Desktop.
WebSockets server tutorial
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 characters
socket.on('data', buffer => { | |
const message = parseMessage(buffer); | |
if (message) { | |
// For our convenience, so we can see what the client sent | |
console.log(message); | |
// We'll just send a hardcoded message in this example | |
socket.write(constructReply({ message: 'Hello from the server!' })); | |
} else if (message === null) { | |
console.log('WebSocket connection closed by the client.'); | |
} | |
}); | |
function constructReply(data) { | |
// TODO: Construct a WebSocket frame Node.js socket buffer | |
} | |
function parseMessage(buffer) { | |
// TODO: Parse the WebSocket frame from the Node.js socket buffer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment