Skip to content

Instantly share code, notes, and snippets.

@Srushtika
Created November 16, 2018 14:56
Show Gist options
  • Save Srushtika/0d4e71152d877ea25f9f248094898ada to your computer and use it in GitHub Desktop.
Save Srushtika/0d4e71152d877ea25f9f248094898ada to your computer and use it in GitHub Desktop.
WebSockets server tutorial
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