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

websocket example error #5

Closed
stevensonmt opened this issue Apr 4, 2020 · 5 comments
Closed

websocket example error #5

stevensonmt opened this issue Apr 4, 2020 · 5 comments

Comments

@stevensonmt
Copy link

not able to run the websocket example. Requesting ws://127.0.0.1:8000/chat results in

ERROR roa::logger > <-- GET / 404 Not Found

@Hexilee
Copy link
Owner

Hexilee commented Apr 4, 2020

Hi, what clients are you using? Could you try this script in browser:

const socket = new WebSocket('ws://127.0.0.1:8000/chat')
socket.addEventListener('open', function (event) {
    socket.send('Hello Server!')
})
socket.addEventListener('message', function (event) {
    console.log('Message from server ', event.data)
})

@stevensonmt
Copy link
Author

stevensonmt commented Apr 4, 2020

When I run that script from codepen.io in firefox it returns in the console:

"Message from server " "Hello Server!"

and the server in the terminal returns:

ERROR websocket_echo > forward err: Connection closed normally

but simply requesting 127.0.0.1:8000/chat in firefox returns in the terminal running the server

ERROR roa::logger > <-- GET /chat 400 Bad Request
invalid websocket upgrade request

Behavior is the same in chromium.

using the URL wss://127.0.0.1:8000/chat seems to work in firefox but not chromium, returning in the terminal running the server:

ERROR websocket_echo > forward err: Connection closed normally

though this is inconsistent.

@Hexilee
Copy link
Owner

Hexilee commented Apr 5, 2020

It seems the socket is closed by codepen after establishing connection.

Browser cannot handle websocket protocol straightly, you should open a web console in any website without security policy.

Could you follow below steps to test websocket example?

  • open a MDN web page in Firefox;
  • open web console by F12 -> Console;
  • run this script:
    const socket = new WebSocket('ws://127.0.0.1:8000/chat')
    socket.addEventListener('open', function (event) {
        socket.send('Hello Server!')
    })
    socket.addEventListener('message', function (event) {
        console.log('Message from server ', event.data)
    })
  • if works well, run socket.send() to send more messages.

@stevensonmt
Copy link
Author

Yes that seems to work, thanks. Is that the expected way for someone to use that example?

@Hexilee
Copy link
Owner

Hexilee commented Apr 5, 2020

Yeah, it is. Could I close this issue if there is no problem else?

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

2 participants