WebSocket(RFC-6455) library written using Swift

Overview

DNWebSocket

Swift 4.2 MIT

Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms.

Tests

Conforms to all necessary Autobahn fuzzing tests. Autobahn

Test results for DNWebSocket you can see here.

In comparison with SocketRocket, this library shows 2-10 times better performance in many Limits/Performance tests.

Cases 6.4.1, 6.4.2, 6.4.3, 6.4.4 received result Non-Strict due to perfomance improvements(it's complicated to validate each fragmented text message)

Installation

Cocoapods

To install DNWebSocket via CocoaPods, get it:

$ gem install cocoapods

Then, create a Podfile in your project root directory:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Target Name>' do
    pod 'DNWebSocket', '~> 1.1.0'
end

And run:

$ pod install

For swift version < 4.2 use 1.0.2 version of pod.

Swift Package Manager

Currently, I'm looking for a generic approach which will allow to use C libraries with all Package Managers. So right now, please, use DNWebSocket-SPM repo.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Swift 4.0 + (but I didn't try earlier versions by the way :D)

Usage

Import library as follows:

import DNWebSocket

Now create websocket, configure it and connect:

let websocket = WebSocket(url: URL(string: "wss://echo.websocket.org:80")!,
                          timeout: 10,
                          protocols: ["chat", "superchat"])

websocket.onConnect = {
    print("connected")
    websocket.sendPing(data: Data())
}

websocket.onData = { (data) in
    websocket.send(data: data)
}

websocket.onText = { (text) in
    websocket.send(string: text)
}

websocket.onPing = { (data) in
    websocket.sendPong(data: data)
}

websocket.onPong = { (data) in
    print("Received pong from server")
}

websocket.onDebugInfo = { (debugInfo) in
    print(debugInfo)
}

websocket.onDisconnect = { (error, closeCode) in
    print("disconnected: \(closeCode)")
}

websocket.connect()

You can create custom connection by accessing .settings and .securitySettings properties:

websocket.settings.timeout = 5 // sec
websocket.settings.debugMode = true // will trigger .onDebugInfo callback and send .debug(String) event
websocket.settings.useCompression = true // false by default
websocket.settings.maskOutputData = true // true by default
websocket.settings.respondPingRequestsAutomatically = true // true by default 
websocket.settings.callbackQueue = .main

websocket.securitySettings.useSSL = false // true by default
websocket.securitySettings.overrideTrustHostname = true // false by default
websocket.securitySettings.trustHostname = /*your hostname*/
websocket.securitySettings.certificateValidationEnabled = true
websocket.securitySettings.cipherSuites = []
You might also like...
Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX
Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OS

iCalSwift - iCalendar(RFC 5545) encoder and decoder for Swift

iCalSwift - iCalendar(RFC 5545) encoder and decoder for Swift

Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM
Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM

AQI Simple iOS app in Swift to show AQI for some cities using websocket using Combine + MVVM This app follows MVVM This app uses combine framework The

A slim implementation of a websocket server using Swift and Vapor 4.0.

Swift Websocket Server Example using Vapor 4.0 This project includes a minimum working example for a websocket server written in Swift. To interact wi

OBSwiftSocket is a Swift library to be used for communication with OBS Studio via obs-websocket (v5).

OBSwiftSocket OBSwiftSocket is a Swift library to be used for communication with OBS Studio via obs-websocket (v5). obs-websocket v5 specification: ht

This is an POC for showing current Air Quality of different Cities in graphical format using webSocket
This is an POC for showing current Air Quality of different Cities in graphical format using webSocket

Air-Quality-Monitoring This is an POC for showing current Air Quality of different Cities in graphical format using webSocket. It Used danielgindi/Cha

A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

AQMonitoring - Air Quality Monitoring App to see live AQI and city data/graph in Swift with WebSocket and MVVM architecture
AQMonitoring - Air Quality Monitoring App to see live AQI and city data/graph in Swift with WebSocket and MVVM architecture

AQMonitoring Air Quality Monitoring App to see live AQI and city data/graph in S

WebSocket implementation for use by Client and Server

WebSocket ⚠️ This module contains no networking. To create a WebSocket Server, see WebSocketServer. To create a WebSocket Client, see WebSocketClient.

Anonymous chat app leveraging Google's Firebase, a NoSQL backend and WebSocket for real time data synching
Anonymous chat app leveraging Google's Firebase, a NoSQL backend and WebSocket for real time data synching

Chaty Chaty is an anonymous chat app that allows millions of users to chat at the same time. Firebase is Google's real time NoSQL Backend as a Service

Proof-of-concept `WKWebview.evaluateJavaScript(...)` replacement for WebSocket-based Javascript execution.

Proof-of-concept `WKWebview.evaluateJavaScript(...)` replacement for WebSocket-based Javascript execution.

CryptoTrackerMenuBar - A Realtime Crypto Tracker macOS Menu Bar App built with SwiftUI & WebSocket
CryptoTrackerMenuBar - A Realtime Crypto Tracker macOS Menu Bar App built with SwiftUI & WebSocket

Realtime Crypto Tracker macOS Menu Bar App - SwiftUI & WebSocket A Realtime Cryp

Cross-platform JsonRPC client implementation with HTTP and WebSocket support

JsonRPC.swift Cross-platform JsonRPC client implementation with HTTP and WebSocket support Getting started Installation Package Manager Add the follow

Enable WebSocket in OPC DA/AE Server with JSON return, first time ever
Enable WebSocket in OPC DA/AE Server with JSON return, first time ever

WebSocket4OPC Enable WebSocket in OPC DA/AE Server with JSON return, first time ever DCOM was developed more than 2 decades ago, wich was the pillar o

Aplikasi CrypTraces adalah MacOS Widget Crypto Tracker dengan SwiftUI, Combine & Cocoa Framework, dan WebSocket & CoinCap API
Aplikasi CrypTraces adalah MacOS Widget Crypto Tracker dengan SwiftUI, Combine & Cocoa Framework, dan WebSocket & CoinCap API

Aplikasi CrypTraces adalah MacOS Widget Crypto Tracker dengan SwiftUI, Combine & Cocoa Framework, dan WebSocket & CoinCap API. Aplikasi ini berbentuk Widget di Menu Bar MacOS dengan menampilkan beberapa Crypto Currency seperti Bitcoin (BTC), Ethereum (ETH), Dogecoin (DOGE), Monero (XMR), dan Litecoin (LTC).

GPU-based media processing library using Metal written in Swift
GPU-based media processing library using Metal written in Swift

GPU-based media processing library using Metal written in Swift. Overview MetalAcc is a GPU-Based media processing library that lets you apply GPU-acc

AsyncHTTP - Generic networking library written using Swift async/await

Generic networking library written using Swift async/await

Releases(1.1.0)
Owner
Gleb Radchenko
Software Engineer @volkswagen previously @babbel. Playing with Solidity 🦍🦧
Gleb Radchenko
A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

Meta Incubator 9.4k Dec 29, 2022
A conforming Objective-C WebSocket client library.

SocketRocket A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS. Test results for SocketRocket here. You can compare to what mod

Meta Incubator 9.4k Dec 29, 2022
AQMonitoring - Air Quality Monitoring App to see live AQI and city data/graph in Swift with WebSocket and MVVM architecture

AQMonitoring Air Quality Monitoring App to see live AQI and city data/graph in S

Kajal Nasit 0 Jan 9, 2022
Websockets in swift for iOS and OSX

Starscream is a conforming WebSocket (RFC 6455) library in Swift. Features Conforms to all of the base Autobahn test suite. Nonblocking. Everything ha

Dalton 7.5k Dec 29, 2022
Fast Websockets in Swift for iOS and OSX

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX. SwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, incl

Josh Baker 1.5k Dec 27, 2022
A collection of socket utilities in pure Swift

SwifterSockets A collection of socket utilities in pure Swift SwifterSockets is part of the Swiftfire webserver project. The Swiftfire website The ref

Rien 58 Sep 9, 2022
WebSocket(RFC-6455) library written using Swift

DNWebSocket Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms. Tests Installation Requirements Usage Tests Conf

Gleb Radchenko 36 Jan 29, 2022
WebSocket(RFC-6455) library written using Swift

DNWebSocket Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms. Tests Installation Requirements Usage Tests Conf

Gleb Radchenko 36 Jan 29, 2022
Starscream is a conforming WebSocket (RFC 6455) library in Swift.

Starscream is a conforming WebSocket (RFC 6455) library in Swift. Features Conforms to all of the base Autobahn test suite. Nonblocking. Everything ha

Dalton 7.5k Jan 7, 2023
SwiftWebSocket - Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX.

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX. SwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, incl

Josh Baker 1.5k Jan 5, 2023