modal-labs / modal-client

Python client library for Modal
https://modal.com/docs
Apache License 2.0
279 stars 38 forks source link

help with websockets #1296

Closed colinator closed 8 months ago

colinator commented 8 months ago

Your documentation says this:

WebSockets
Functions annotated with @web_endpoint, @asgi_app, or @wsgi_app also support the WebSocket protocol. Consult your web framework for appropriate documentation on how to use WebSockets with that library.

WebSockets on Modal maintain a single function call per connection, which can be useful for keeping state around. Most of the time, you will want to set your handler function to [allow concurrent inputs](https://modal.com/docs/guide/concurrent-inputs), which allows multiple simultaneous WebSocket connections to be handled by the same container.

We support the full WebSocket protocol as per [RFC 6455](https://www.rfc-editor.org/rfc/rfc6455), but we do not yet have support for [RFC 8441](https://www.rfc-editor.org/rfc/rfc8441) (WebSockets over HTTP/2) or [RFC 7692](https://datatracker.ietf.org/doc/html/rfc7692) (permessage-deflate extension). WebSocket messages can be up to 2 MiB each.

... but I can't figure out how to actually make it work... could you create an example please?

ekzhang commented 8 months ago

See https://fastapi.tiangolo.com/advanced/websockets/?h=websocket :)

You can use the app directly with our @asgi_app decorator