All Projects → tidwall → Swiftwebsocket

tidwall / Swiftwebsocket

Licence: mit
Fast Websockets in Swift for iOS and OSX

Programming Languages

swift
15916 projects
go
31211 projects - #10 most used programming language
shell
77523 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Swiftwebsocket

Kitura Net
Kitura networking
Stars: ✭ 98 (-93.39%)
Mutual labels:  networking
Autowire
Automatically configure Wireguard interfaces in distributed system. It supports Consul as backend.
Stars: ✭ 101 (-93.19%)
Mutual labels:  networking
React Native Networking
react-native module to download and upload files
Stars: ✭ 105 (-92.92%)
Mutual labels:  networking
Solarnetwork
Elegant network abstraction layer in Swift.
Stars: ✭ 99 (-93.32%)
Mutual labels:  networking
Joynet
high performance network (tcp socket) library for lua, based on https://github.com/IronsDu/brynet and lua coroutine.
Stars: ✭ 101 (-93.19%)
Mutual labels:  networking
Manuf
Parser library for Wireshark's OUI database.
Stars: ✭ 103 (-93.05%)
Mutual labels:  networking
Netfil
A kernel network manager with monitoring and limiting capabilities for macOS. #nsacyber
Stars: ✭ 97 (-93.46%)
Mutual labels:  networking
Rxalamofire
RxSwift wrapper around the elegant HTTP networking in Swift Alamofire
Stars: ✭ 1,503 (+1.35%)
Mutual labels:  networking
Windows 10 Hardening
Windows 10 hardening guide without gimmicks
Stars: ✭ 102 (-93.12%)
Mutual labels:  networking
Gnmic
gnmic a gnmi CLI client and collector
Stars: ✭ 105 (-92.92%)
Mutual labels:  networking
Gossip Python
Implementation of the gossip protocol
Stars: ✭ 100 (-93.26%)
Mutual labels:  networking
Hover
Async network layer with Combine
Stars: ✭ 101 (-93.19%)
Mutual labels:  networking
Gke Networking Demos
This project presents a number of best practices for establishing network links between Kubernetes Engine clusters, and exposing cluster services across Google Cloud projects. You will use a set of Deployment Manager templates to create networks, subnets, vpn connections, and Kubernetes Engine clusters.
Stars: ✭ 104 (-92.99%)
Mutual labels:  networking
Proxy
C++ TCP Proxy Server
Stars: ✭ 98 (-93.39%)
Mutual labels:  networking
Alamofire
Elegant HTTP Networking in Swift
Stars: ✭ 36,896 (+2387.93%)
Mutual labels:  networking
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-93.39%)
Mutual labels:  networking
Facil.io
Your high performance web application C framework
Stars: ✭ 1,393 (-6.07%)
Mutual labels:  networking
Pylinkvalidator
pylinkvalidator is a standalone and pure python link validator and crawler that traverses a web site and reports errors (e.g., 500 and 404 errors) encountered.
Stars: ✭ 109 (-92.65%)
Mutual labels:  networking
Colyseus Examples
Colyseus Game Server examples for learning purposes
Stars: ✭ 109 (-92.65%)
Mutual labels:  networking
Opc Ua Ooi
Object Oriented Internet - C# deliverables supporting a new Machine To Machine (M2M) communication architecture
Stars: ✭ 104 (-92.99%)
Mutual labels:  networking

 SwiftWebSocket

API Docs Swift/5.0 Build Status

Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX.

SwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, including strict UTF-8, and message compression.

Project Status

I'm looking for someone to help with or take over maintenance of this project.

Features

  • High performance.
  • 100% conforms to Autobahn Tests. Including base, limits, compression, etc. Test results.
  • TLS / WSS support. Self-signed certificate option.
  • The API is modeled after the Javascript API.
  • Reads compressed messages (permessage-deflate). RFC 7692
  • Send pings and receive pong events.
  • Strict UTF-8 processing.
  • binaryType property to choose between [UInt8] or NSData messages.
  • Zero asserts. All networking, stream, and protocol errors are routed through the error event.
  • iOS / Objective-C support.

Example

func echoTest(){
    var messageNum = 0
    let ws = WebSocket("wss://echo.websocket.org")
    let send : ()->() = {
        messageNum += 1
        let msg = "\(messageNum): \(NSDate().description)"
        print("send: \(msg)")
        ws.send(msg)
    }
    ws.event.open = {
        print("opened")
        send()
    }
    ws.event.close = { code, reason, clean in
        print("close")
    }
    ws.event.error = { error in
        print("error \(error)")
    }
    ws.event.message = { message in
        if let text = message as? String {
            print("recv: \(text)")
            if messageNum == 10 {
                ws.close()
            } else {
                send()
            }
        }
    }
}

Custom Headers

var request = URLRequest(url: URL(string:"ws://url")!)
request.addValue("AUTH_TOKEN", forHTTPHeaderField: "Authorization")
request.addValue("Value", forHTTPHeaderField: "X-Another-Header")
let ws = WebSocket(request: request)

Reuse and Delaying WebSocket Connections

v2.3.0+ makes available an optional open method. This will allow for a WebSocket object to be instantiated without an immediate connection to the server. It can also be used to reconnect to a server following the close event.

For example,

let ws = WebSocket()
ws.event.close = { _,_,_ in
    ws.open()                 // reopen the socket to the previous url
    ws.open("ws://otherurl")  // or, reopen the socket to a new url
}
ws.open("ws://url") // call with url

Compression

The compression flag may be used to request compressed messages from the server. If the server does not support or accept the request, then connection will continue as normal, but with uncompressed messages.

let ws = WebSocket("ws://url")
ws.compression.on = true

Self-signed SSL Certificate

let ws = WebSocket("ws://url")
ws.allowSelfSignedSSL = true

Network Services (VoIP, Video, Background, Voice)

// Allow socket to handle VoIP in the background.
ws.services = [.VoIP, .Background] 

Installation (iOS and OS X)

Carthage

Add the following to your Cartfile:

github "tidwall/SwiftWebSocket"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

The import SwiftWebSocket directive is required in order to access SwiftWebSocket features.

CocoaPods

Add the following to your Podfile:

use_frameworks!
pod 'SwiftWebSocket'

Then run pod install with CocoaPods 0.36 or newer.

The import SwiftWebSocket directive is required in order to access SwiftWebSocket features.

Manually

Copy the SwiftWebSocket/WebSocket.swift file into your project.
You must also add the libz.dylib library. Project -> Target -> Build Phases -> Link Binary With Libraries

There is no need for import SwiftWebSocket when manually installing.

Contact

Josh Baker @tidwall

License

SwiftWebSocket source code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].