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...
RSNetworking is a networking library written entirly for the Swift programming language.

RSNetworking is a networking library written entirly for the Swift programming language.

ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

A new, clean and lean network interface reachability library written in Swift.

Reachability A new, clean and lean network interface reachability library written in Swift. Remarks Network reachability changes can be monitored usin

FakeGithub is an iOS application written using Objective-C
FakeGithub is an iOS application written using Objective-C

FakeGithub FakeGithub is an iOS application written using Objective-C. Opensource this project for learning purpose. Hope this could be a little usefu

An awesome Swift HTML DSL library using result builders.

SwiftHtml An awesome Swift HTML DSL library using result builders. let doc = Document(.html5) { Html { Head { Meta()

Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

A reactive library for using URLSession

Reactive wrapper for URLSession using Combine. At its core, the library consist of the NetworkServiceClient protocol along with a minimal implementation NetworkService.

SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Releases(1.1.0)
Owner
Gleb Radchenko
Software Engineer @volkswagen previously @babbel. Playing with Solidity 🦍🦧
Gleb Radchenko
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

Amey Vikkram Tiwari 2 Nov 6, 2022
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

Adrian Hupka 5 Sep 22, 2022
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

Edon 3 Sep 28, 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

Facebook Incubator 9.4k Dec 27, 2022
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.

Zewo Graveyard 63 Jan 29, 2022
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

Tesseract 5 Oct 19, 2022
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

null 13 Dec 14, 2022
AsyncHTTP - Generic networking library written using Swift async/await

Generic networking library written using Swift async/await

Laszlo Teveli 7 Aug 3, 2022
Alamofire Network Layer written in swift 5 using the protocol oriented, combine, UIKit, MVVM.

CoreAPI-iOS This project Contains Alamofire Network layer Based on Protocol Oriented Concept and Combine Framework. It is created with UIKit, Alamofir

Mehran Kamalifard 27 Nov 11, 2022
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022