Skip to content

DitchOoM/websocket

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


WebSocket

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
  1. About The Project
  2. Installation
  3. Usage
  4. Building Locally
  5. Getting Started
  6. Roadmap
  7. Contributing
  8. License

About The Project

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.

Runtime Dependencies

Platform 🛠Builds🛠 + 🔬Tests🔬
JVM 1.8 🚀
Node.js 🚀
Browser (Chrome) 🚀
Android 🚀
iOS 🚀
WatchOS 🚀
TvOS 🚀
MacOS 🚀
Linux X64 🔮
Windows X64 🔮

Installation

  • Add implementation("com.ditchoom:websocket:$version") to your build.gradle dependencies
  • Copy the contents of this patch.js file into your own webpack.config.d directory if you are targeting js
  • 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"
            }
        }
    }
}

Client WebSocket Usage

Suspend connect read write and close

// 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()

TLS support

// Simply add tls=true or change
val connectionOptions = WebSocketConnectionOptions(name = "localhost", port = 443, websocketEndpoint = "/echo", tls = true)

Building Locally

Roadmap

See the open issues for a list of proposed features ( and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

About

Simple kotlin multiplatform websocket wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published