Created
November 16, 2018 14:56
-
-
Save Srushtika/0d4e71152d877ea25f9f248094898ada 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.'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment