1
0
mirror of https://github.com/actix/actix-website synced 2024-12-18 09:53:12 +01:00
actix-website/docs/websockets.md

23 lines
944 B
Markdown
Raw Permalink Normal View History

2018-05-22 23:15:08 +02:00
---
title: WebSockets
2018-05-22 23:15:08 +02:00
---
import CodeBlock from "@site/src/components/code_block";
# WebSockets
Actix Web supports a high-level WebSocket interface via the `actix-ws` crate. Using this crate, it's possible to convert a request's `Payload` stream into a stream of [_ws::Message_][message]s and then react to them inside a spawned async task.
2018-05-22 23:15:08 +02:00
The following is an example of a simple WebSocket echo server:
2018-05-22 23:15:08 +02:00
<CodeBlock example="websockets" file="main.rs" section="websockets" />
2018-05-22 23:15:08 +02:00
> A simple WebSocket echo server example is available [in the examples repo][echo].
2018-05-22 23:15:08 +02:00
> An example chat server is also available [in the examples directory][chat]
[message]: https://docs.rs/actix-ws/0.3/actix_ws/enum.Message.html
2022-03-06 00:55:35 +01:00
[payload]: https://docs.rs/actix-web/4/actix_web/web/struct.Payload.html
[echo]: https://github.com/actix/examples/tree/master/websockets/echo-actorless
[chat]: https://github.com/actix/examples/tree/master/websockets/chat-actorless