TesseractWebSocket 0.2.0

TesseractWebSocket 0.2.0

Maintained by Yehor Popovych.



 
Depends on:
SwiftNIO~> 2.40.0
SwiftNIOHTTP1~> 2.40.0
SwiftNIOWebSocket~> 2.40.0
SwiftNIOConcurrencyHelpers~> 2.40.0
SwiftNIOFoundationCompat~> 2.40.0
SwiftNIOSSL~> 2.19.0
 

  • By
  • Tesseract Systems, Inc.

WebSocket.swift

🐧 linux: ready GitHub license Build Status GitHub release SPM compatible CocoaPods version Platform OS X | iOS | tvOS | watchOS | Linux

Cross-platform WebSocket client implementation based on Swift NIO

Goals

We have good WebSocket libraries for Apple platforms, but we need it on Linux too. This library based on Apple Swift NIO framework, which allows it to be cross-platform.

Getting started

Installation

Package Manager

Add the following dependency to your Package.swift:

.package(url: "https://github.com/tesseract-one/WebSocket.swift.git", from: "0.2.0")

Run swift build and build your app.

CocoaPods

Add the following to your Podfile:

pod 'TesseractWebSocket.swift', '~> 0.2'

Then run pod install

Examples

Echo Connection

import Foundation
import WebSocket

let socket = WebSocket()

socket.onConnected = { ws in
  ws.send("hello")
}

socket.onData = { data, ws in
  print("Received", data)
  assert(data.text! == "hello")
  ws.disconnect()
}

socket.connect(url: URL(string: "wss://echo.websocket.org")!)

WARNING! You should always disconnect WebSocket. It will leak otherwise! And will leak thread too!

Author

License

WebSocket.swift is available under the Apache 2.0 license. See the LICENSE file for more information.