
RFC 6455-compliant WebSocket client with permessage-deflate compression, suspend-friendly I/O and Flow-based messages, zero-copy frame pipeline, SIMD-optimized masking, and Autobahn compliance.
See the project website for documentation and APIs.
WebSocket is a Kotlin Multiplatform library providing RFC 6455 compliant WebSocket client functionality with permessage-deflate compression (RFC 7692).
AsynchronousSocketChannel (NIO2)NWConnection via Network.frameworkincomingMessages: Flow<WebSocketMessage>
dependencies {
implementation("com.ditchoom:websocket:<latest-version>")
}Find the latest version on Maven Central.
val options = WebSocketConnectionOptions(
name = "echo.websocket.org",
port = 443,
tls = true,
)
val client = WebSocketClient.allocate(options).connect()
// Send a message
client.write("Hello, WebSocket!")
// Receive messages
client.incomingMessages.collect { message ->
when (message) {
is WebSocketMessage.Text -> println("Received: ${message.value}")
is WebSocketMessage.Binary -> println("Binary: ${message.value.remaining()} bytes")
}
}
client.close()Request permessage-deflate compression for reduced bandwidth:
val options = WebSocketConnectionOptions(
name = "example.com",
requestCompression = true,
compressionOptions = CompressionOptions(
clientNoContextTakeover = false, // maintain LZ77 window across messages
serverNoContextTakeover = false,
),
)| Platform | Implementation | Compression |
|---|---|---|
| JVM 1.8+ | NIO2 AsyncSocketChannel | Context takeover, max_window_bits=15 |
| Android | Same as JVM | Same as JVM |
| iOS/macOS/tvOS/watchOS | NWConnection | Context takeover |
| Linux x64/ARM64 | io_uring / epoll | Context takeover + custom window bits |
| Node.js | Native WebSocket | No context takeover |
| Browser | Native WebSocket | Handled by browser |
Copyright 2022 DitchOoM
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
See the project website for documentation and APIs.
WebSocket is a Kotlin Multiplatform library providing RFC 6455 compliant WebSocket client functionality with permessage-deflate compression (RFC 7692).
AsynchronousSocketChannel (NIO2)NWConnection via Network.frameworkincomingMessages: Flow<WebSocketMessage>
dependencies {
implementation("com.ditchoom:websocket:<latest-version>")
}Find the latest version on Maven Central.
val options = WebSocketConnectionOptions(
name = "echo.websocket.org",
port = 443,
tls = true,
)
val client = WebSocketClient.allocate(options).connect()
// Send a message
client.write("Hello, WebSocket!")
// Receive messages
client.incomingMessages.collect { message ->
when (message) {
is WebSocketMessage.Text -> println("Received: ${message.value}")
is WebSocketMessage.Binary -> println("Binary: ${message.value.remaining()} bytes")
}
}
client.close()Request permessage-deflate compression for reduced bandwidth:
val options = WebSocketConnectionOptions(
name = "example.com",
requestCompression = true,
compressionOptions = CompressionOptions(
clientNoContextTakeover = false, // maintain LZ77 window across messages
serverNoContextTakeover = false,
),
)| Platform | Implementation | Compression |
|---|---|---|
| JVM 1.8+ | NIO2 AsyncSocketChannel | Context takeover, max_window_bits=15 |
| Android | Same as JVM | Same as JVM |
| iOS/macOS/tvOS/watchOS | NWConnection | Context takeover |
| Linux x64/ARM64 | io_uring / epoll | Context takeover + custom window bits |
| Node.js | Native WebSocket | No context takeover |
| Browser | Native WebSocket | Handled by browser |
Copyright 2022 DitchOoM
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.