A kotlin multiplatform library that allows you to connect a client websocket to websocket server.
Fully tested on all platforms using the extensive Autobahn test suite.
Report Bug
·
Request Feature
Table of Contents
Managing a websocket client can be slightly different based on each platform. This project aims to make it easier to manage websockets in a cross platform way using kotlin multiplatform. This was originally created as a side project for a kotlin multiplatform mqtt data sync solution.
| Platform | 🛠Builds🛠 + 🔬Tests🔬 |
|---|---|
JVM 1.8 |
🚀 |
Node.js |
🚀 |
Browser (Chrome) |
🚀 |
Android |
🚀 |
iOS |
🚀 |
WatchOS |
🚀 |
TvOS |
🚀 |
MacOS |
🚀 |
Linux X64 |
🔮 |
Windows X64 |
🔮 |
- Add
implementation("com.ditchoom:websocket:$version")to yourbuild.gradledependencies - Copy the contents of this patch.js file
into
your own
webpack.config.ddirectory if you are targetingjs - Add this to your
kotlin {bracket in build.gradle.kts if you are targeting an apple platform
kotlin {
...
cocoapods {
ios.deploymentTarget = "13.0"
osx.deploymentTarget = "11.0"
watchos.deploymentTarget = "6.0"
tvos.deploymentTarget = "13.0"
pod("SocketWrapper") {
source = git("https://github.com/DitchOoM/apple-socket-wrapper.git") {
tag = "0.1.1"
}
}
}
}
// Run in a coroutine scope
val connectionOptions = WebSocketConnectionOptions(name = "localhost", port = 8081, websocketEndpoint = "/echo")
val websocket = WebSocketClient.Companion.allocate(connectionOptions)
websocket.connect()
val string1 = "test"
websocket.write(string1)
val dataRead = websocket.read() as DataRead.StringDataRead
val stringReceived = dataRead.string
websocket.close()// Simply add tls=true or change
val connectionOptions = WebSocketConnectionOptions(name = "localhost", port = 443, websocketEndpoint = "/echo", tls = true)
git clone git@github.com:DitchOoM/websocket.git- Open cloned directory with Intellij IDEA.
- Be sure to open with gradle
See the open issues for a list of proposed features ( and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache 2.0 License. See LICENSE for more information.