# codetics-ocpp-ws
A small WebSocket implementation for OCPP-J, written for servers holding tens of thousands of long-lived connections:
- RFC 6455 framing, fragmentation, control frames and close handshake;
- RFC 7692 permessage-deflate, which OCPP 2.0.1 and 2.1 require from a CSMS, with a memory profile suited
to idle connections (pooled compressors, lazily allocated decompressors);
- a cancel-safe reader (`WsReader::recv`) and a separate writer, so one task can multiplex reads, timers and commands;
- a minimal client (`client::connect` / `client::handshake`) for simulators and tests.
The HTTP upgrade is left to your HTTP server (hyper, axum, …): wrap the upgraded stream with `server()`.
```rust,no_run
use codetics_ocpp_ws::{Message, WsConfig, close_code};
async fn session<S: tokio::io::AsyncRead + tokio::io::AsyncWrite>(upgraded: S) {
let (mut reader, mut writer) = codetics_ocpp_ws::server(upgraded, WsConfig::default(), None);
while let Ok(Some(msg)) = reader.recv().await {
match msg {
Message::Text(text) => writer.send_text(&text).await.unwrap(),
Message::Ping(data) => writer.send_pong(&data).await.unwrap(),
Message::Close(_) => {
let _ = writer.send_close(close_code::NORMAL, "").await;
break;
}
_ => {}
}
}
}
```
## Part of Codetics OCPP
This crate belongs to [Codetics OCPP](https://codetics.fr), a complete OCPP 1.6J / 2.0.1 / 2.1
implementation in Rust written by **Kevin Vavelin** ([Codetics](https://codetics.fr)).
It can be used as is; contributions are welcome.
## License and credit
Licensed under the [Apache License, Version 2.0](LICENSE).
Copyright 2026 Kevin Vavelin, Codetics. Any redistribution of this crate or of a work derived
from it (including forks and products embedding it) must keep the copyright notice and include
the [NOTICE](NOTICE) file crediting Kevin Vavelin / Codetics as the origin of the work.