1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

format markdown

This commit is contained in:
Rob Ede
2022-03-06 00:43:10 +00:00
parent f27cc4b6b4
commit e239414a55
31 changed files with 165 additions and 188 deletions

View File

@ -1,26 +1,25 @@
# Websocket chat broker example
This is a different implementation of the
[websocket chat example](https://github.com/actix/examples/tree/master/websockets/chat)
This is a different implementation of the [websocket chat example](https://github.com/actix/examples/tree/master/websockets/chat)
Differences:
* Chat Server Actor is a System Service that runs in the same thread as the HttpServer/WS Listener.
* The [actix-broker](https://github.com/Chris-Ricketts/actix-broker) crate is used to facilitate the sending of some messages between the Chat Session and Server Actors where the session does not require a response.
* The Client is not required to send Ping messages. The Chat Server Actor auto-clears dead sessions.
- Chat Server Actor is a System Service that runs in the same thread as the HttpServer/WS Listener.
- The [actix-broker](https://github.com/Chris-Ricketts/actix-broker) crate is used to facilitate the sending of some messages between the Chat Session and Server Actors where the session does not require a response.
- The Client is not required to send Ping messages. The Chat Server Actor auto-clears dead sessions.
Possible Improvements:
* Could the Chat Server Actor be simultaneously a System Service (accessible to the Chat Session via the System Registry) and also run in a separate thread?
- Could the Chat Server Actor be simultaneously a System Service (accessible to the Chat Session via the System Registry) and also run in a separate thread?
## Server
Chat server listens for incoming tcp connections. Server can access several types of message:
* `/list` - list all available rooms
* `/join name` - join room, if room does not exist, create new one
* `/name name` - set session name
* `some message` - just string, send message to all peers in same room
- `/list` - list all available rooms
- `/join name` - join room, if room does not exist, create new one
- `/name name` - set session name
- `some message` - just string, send message to all peers in same room
To start server use command: `cargo run`

View File

@ -1,7 +1,6 @@
# Websocket chat example
This is extension of the
[actix chat example](https://github.com/actix/actix/tree/master/examples/chat)
This is extension of the [actix chat example](https://github.com/actix/actix/tree/master/examples/chat)
Added features:

View File

@ -1,27 +1,25 @@
# Websocket chat example
This is extension of the
[actix chat example](https://github.com/actix/actix/tree/master/examples/chat)
This is extension of the [actix chat example](https://github.com/actix/actix/tree/master/examples/chat)
Added features:
* Browser WebSocket client
* Chat server runs in separate thread
* Tcp listener runs in separate thread
* Application state is shared with the websocket server and a resource at `/count/`
- Browser WebSocket client
- Chat server runs in separate thread
- Tcp listener runs in separate thread
- Application state is shared with the websocket server and a resource at `/count/`
## Server
1. Chat server listens for incoming tcp connections. Server can access several types of message:
* `/list` - list all available rooms
* `/join name` - join room, if room does not exist, create new one
* `/name name` - set session name
* `some message` - just string, send message to all peers in same room
* client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets dropped
- `/list` - list all available rooms
- `/join name` - join room, if room does not exist, create new one
- `/name name` - set session name
- `some message` - just string, send message to all peers in same room
- client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets dropped
2. [http://localhost:8080/count/](http://localhost:8080/count/) is a
non-websocket endpoint and will affect and display state.
2. [http://localhost:8080/count/](http://localhost:8080/count/) is a non-websocket endpoint and will affect and display state.
To start server use command: `cargo run --bin websocket-chat-server`

View File

@ -25,10 +25,10 @@ cargo run --bin websocket-client
### python client
- ``pip install aiohttp``
- ``python websocket-client.py``
- `pip install aiohttp`
- `python websocket-client.py`
if ubuntu :
- ``pip3 install aiohttp``
- ``python3 websocket-client.py``
- `pip3 install aiohttp`
- `python3 websocket-client.py`