-
-
Notifications
You must be signed in to change notification settings - Fork 540
Questions about consumer_handler and registration examples in intro #457
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
Comments
For anyone who finds this the answer is:
|
That's what If you want to avoid displaying a stack trace: try:
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
pass
Yes.
It'd be better to think of it as an (async) iterator than a while True loop.
This is a bit hidden in the documentation, here: https://websockets.readthedocs.io/en/stable/api.html#websockets.protocol.WebSocketCommonProtocol: "The iterator yields incoming messages. It exits normally when the connection is closed with the status code 1000 (OK) or 1001 (going away). It raises a ConnectionClosed exception when the connection is closed with any other status code." I'll consider improving the docs.
It depends whether you're writing a server or a client — you didn't specify. Both cases are covered here: https://websockets.readthedocs.io/en/stable/intro.html#secure-example
The code you provided suggests you misunderstood the API of |
Just saw your second comment... If you're writing a client ( The revised code example is sensible (just a couple typos). |
Thanks for the reply anyway. I definitely am writing a client. The API section in the documentation was a great help. |
Consumer Handler Question
Hi, I was looking at the consumer_handler example in the intro. I was wondering if you could help me figure out how to have this example run forever (i.e. until CTRL + C).
Here is a modification of the example in the intro,
This code will print every message sent from
websocket
, correct?Under the example, it says
Does this mean
consumer_handler
is effectively awhile True
loop? And "when the client disconnects," does the loop exit or is an error (ConnectionClosed
?) raised? How could I use this same example but withssl
?Registration/ Multiple Connection Question
How could I run
consumer_handler
for multiple WebSocket connections?Would the below code work? (Modified from the original registration example)
I am currently just learning how to use WebSockets, so your help is very much appreciated. Obviously, thanks for creating such an awesome library.
The text was updated successfully, but these errors were encountered: