Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nurmohammed840/websocket.rs
WebSocket implementation for both client and server
https://github.com/nurmohammed840/websocket.rs
websocket
Last synced: 3 months ago
JSON representation
WebSocket implementation for both client and server
- Host: GitHub
- URL: https://github.com/nurmohammed840/websocket.rs
- Owner: nurmohammed840
- License: apache-2.0
- Created: 2022-04-11T17:22:00.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-17T02:52:44.000Z (10 months ago)
- Last Synced: 2024-10-13T11:27:13.008Z (4 months ago)
- Topics: websocket
- Language: Rust
- Homepage: https://docs.rs/web-socket
- Size: 251 KB
- Stars: 85
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Introduction
This library is an implementation of the [WebSocket](https://en.wikipedia.org/wiki/WebSocket) protocol, which provides a way for two-way communication between a client and server over a single TCP connection. This library provides [fastest](https://github.com/nurmohammed840/web-socket-benchmark) and intuitive WebSocket implementation for both client and server-side applications.
## Installation
To use this library, add it as a dependency to your Rust project by adding the following line to your `Cargo.toml` file:
```toml
[dependencies]
web-socket = "0.7"
```### Example
You can run this example with: `cargo run --example minimal`
```rust no_run
use tokio::io::*;
use web_socket::*;async fn example(mut ws: WebSocket) -> Result<()>
where
IO: Unpin + AsyncRead + AsyncWrite,
{
for _ in 0..3 {
ws.send("Copy Cat!").await?;match ws.recv_event().await? {
Event::Data { ty, data } => {
assert!(matches!(ty, DataType::Complete(MessageType::Text)));
assert_eq!(&*data, b"Copy Cat!");
}
Event::Ping(data) => ws.send_pong(data).await?,
Event::Pong(..) => {}
Event::Error(..) => return ws.close(CloseCode::ProtocolError).await,
Event::Close { .. } => return ws.close(()).await,
}
}
ws.close("bye!").await
}
```For more examples, see [./examples](https://github.com/nurmohammed840/websocket.rs/tree/master/examples) directory.
It passed all test of the [autobahn testsuite](https://github.com/crossbario/autobahn-testsuite)
### Non goals
- [Websocket protocol handshake](https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake)
- [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security)#### License
This project is licensed under [Apache License 2.0](https://github.com/nurmohammed840/websocket.rs/blob/master/LICENSE)