WebSocket

2.5.2

shareup/websocket-apple

What's New

v2.5.2

2022-11-04T23:46:25Z
  • Update dependencies

WebSocket wrapper around URLSessionWebSocketTask

(macOS, iOS, iPadOS, tvOS, and watchOS)

A concrete implementation of a WebSocket client implemented by wrapping Apple's URLSessionWebSocketTask and conforming to WebSocketProtocol. WebSocket exposes a simple API and conforms to Apple's Combine Publisher.

Usage

let socket = WebSocket(url: url(49999))

let sub = socket.sink(
	receiveCompletion: { print("Socket closed: \(String(describing: $0))") },
	receiveValue: { (result) in
		switch result {
		case .success(.open):
			socket.send("First message")
		case .success(.string(let incoming)):
			print("Received \(incoming)")
		case .failure:
			socket.close()
		default:
			break
		}
	}
)
defer { sub.cancel() }

socket.connect()

Tests

  1. In your Terminal, navigate to the websocket-apple directory
  2. Run the tests using swift test

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Thu Nov 10 2022 12:45:44 GMT-0500 (GMT-05:00)