Websocket won't broadcast


everything has been working up till i tried to send the message out to other browsers. my code looks right, but i must have missed something. the real problem is that i am not getting any error messages anywhere so i have nothing to go on.

here is what i believe is the relevant code:
// Exercise 5: Respond to connection events
// Exercise 6: Respond to client messages
// Exercise 7: Send a message back to the client, echoing the message received
// Exercise 8: Broadcast messages received to all other clients

wsServer.on(‘connection’, (socket)=>{
console.log(‘A new client has connected to the server!’);
socket.on(‘message’, (data)=>{
console.log('data received: ’ + data);
broadcast(data, socket);

////////////// HELPER FUNCTIONS ///////////////
function broadcast(data, socketToOmit) {
// Exercise 8: Implement the broadcast pattern. Exclude the emitting socket!
wsServer.clients.forEach(connectedSocket => {
if (connectedSocket.readyState === WebSocket.OPEN && connectedSocket !== socketToOmit ) {

function sendMessageToServer(message) {
// Make sure the client is connected to the ws server
if (!wsClient) {
showMessageReceived(‘No WebSocket connection :(’);

  // TODO:
  // Exercise 6: Send the message from the messageBox to the server
  // Exercise 9: Send the message in a custom message object with .type and .payload properties

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.