Fill in the gaps to complete the code that handles text and binary messages on websocket server.
Websocket server
Handling text and binary messages
Report a typo
Fill in the gaps with the relevant elements
ws.on('message', function message(data) {
if ( typeof data === '') {
// Handle text message
console.log('Received text message: %s', data);
// Echo the text message back to the client
ws.send(`You sent -> ${data}`);
} else if (data instanceof ) {
// Handle binary message
console.log('Received binary message of %d bytes', .length);
// Echo the binary message back to the client
ws.send(data);
}
});Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.