Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1.4 WebSocket Messages: feat: send message from the frontend to the backend error #2

Open
salybu opened this issue Mar 28, 2022 · 0 comments

Comments

@salybu
Copy link
Owner

salybu commented Mar 28, 2022

unexpected log

The frontend should send a message to the backend 10s after the app runs on this commit. and then the message from the frontend should be printed on the server (terminal) console. but on the terminal, unexpected log like below are shown and cannot read a message from frontend.

<Buffer 68 65 6c 6c 6f 20 66 72 6f 6d 20 74 68 65 20 62 72 6f 77 73 65 72 21>

solutions

  • just change the code from message to message.toString("utf-8"). previous code doesn't work because of new 'ws' version
/* server.js */
  socket.on("message", (message) => {
    // [X] console.log(message);
    console.log(message.toString("utf-8"));
  });

reference

  • nomad coder colleagues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant