
Stream-based WebSocket implementation (RFC6455) offering sync and async APIs, TLS support, Autobahn-tested, and a faithful line-by-line transliteration with provenance headers.
This is a Kotlin Multiplatform line-by-line transliteration port of snapview/tungstenite-rs.
Original Project: This port is based on snapview/tungstenite-rs. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/snapview/tungstenite-rs. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Lightweight stream-based WebSocket implementation for Rust.
use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::accept;
/// A WebSocket echo server
fn main () {
let server = TcpListener::bind("127.0.0.1:9001").unwrap();
for stream in server.incoming() {
spawn (move || {
let mut websocket = accept(stream.unwrap()).unwrap();
loop {
let msg = websocket.read().unwrap();
// We do not want to send back ping/pong messages.
if msg.is_binary() || msg.is_text() {
websocket.send(msg).unwrap();
}
}
});
}
}Take a look at the examples section to see how to write a simple client/server.
NOTE: tungstenite-rs is more like a barebone to build reliable modern networking applications
using WebSockets. If you're looking for a modern production-ready "batteries included" WebSocket
library that allows you to efficiently use non-blocking sockets and do "full-duplex" communication,
take a look at tokio-tungstenite.
This library provides an implementation of WebSockets, RFC6455. It allows for both synchronous (like TcpStream) and asynchronous usage and is easy to integrate into any third-party event loops including MIO. The API design abstracts away all the internals of the WebSocket protocol but still makes them accessible for those who wants full control over the network.
It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula of tungsten disulfide, the tungstenite mineral.
Tungstenite provides a complete implementation of the WebSocket specification.
TLS is supported on all platforms using native-tls or rustls. The following
features are available:
native-tlsnative-tls-vendoredrustls-tls-native-rootsrustls-tls-webpki-rootsChoose the one that is appropriate for your needs.
By default no TLS feature is activated, so make sure you use one of the TLS features, otherwise you won't be able to communicate with the TLS endpoints.
There is no support for permessage-deflate at the moment, but the PRs are welcome 😉
Tungstenite is thoroughly tested and passes the Autobahn Test Suite for WebSockets. It is also covered by internal unit tests as well as possible.
Benches are in ./benches.
cargo bench --bench \* -- --quick --noplot
cargo bench --bench e2e -- --quick --noplot
Please report bugs and make feature requests here.
dependencies {
implementation("io.github.kotlinmania:tungstenite-kotlin:0.2.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream snapview/tungstenite-rs. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the tungstenite-rs authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the snapview/tungstenite-rs maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of snapview/tungstenite-rs.
Original Project: This port is based on snapview/tungstenite-rs. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/snapview/tungstenite-rs. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Lightweight stream-based WebSocket implementation for Rust.
use std::net::TcpListener;
use std::thread::spawn;
use tungstenite::accept;
/// A WebSocket echo server
fn main () {
let server = TcpListener::bind("127.0.0.1:9001").unwrap();
for stream in server.incoming() {
spawn (move || {
let mut websocket = accept(stream.unwrap()).unwrap();
loop {
let msg = websocket.read().unwrap();
// We do not want to send back ping/pong messages.
if msg.is_binary() || msg.is_text() {
websocket.send(msg).unwrap();
}
}
});
}
}Take a look at the examples section to see how to write a simple client/server.
NOTE: tungstenite-rs is more like a barebone to build reliable modern networking applications
using WebSockets. If you're looking for a modern production-ready "batteries included" WebSocket
library that allows you to efficiently use non-blocking sockets and do "full-duplex" communication,
take a look at tokio-tungstenite.
This library provides an implementation of WebSockets, RFC6455. It allows for both synchronous (like TcpStream) and asynchronous usage and is easy to integrate into any third-party event loops including MIO. The API design abstracts away all the internals of the WebSocket protocol but still makes them accessible for those who wants full control over the network.
It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula of tungsten disulfide, the tungstenite mineral.
Tungstenite provides a complete implementation of the WebSocket specification.
TLS is supported on all platforms using native-tls or rustls. The following
features are available:
native-tlsnative-tls-vendoredrustls-tls-native-rootsrustls-tls-webpki-rootsChoose the one that is appropriate for your needs.
By default no TLS feature is activated, so make sure you use one of the TLS features, otherwise you won't be able to communicate with the TLS endpoints.
There is no support for permessage-deflate at the moment, but the PRs are welcome 😉
Tungstenite is thoroughly tested and passes the Autobahn Test Suite for WebSockets. It is also covered by internal unit tests as well as possible.
Benches are in ./benches.
cargo bench --bench \* -- --quick --noplot
cargo bench --bench e2e -- --quick --noplot
Please report bugs and make feature requests here.
dependencies {
implementation("io.github.kotlinmania:tungstenite-kotlin:0.2.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream snapview/tungstenite-rs. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the tungstenite-rs authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the snapview/tungstenite-rs maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.