https://github.com/hummingbird-project/swift-websocket
Support for WebSockets
https://github.com/hummingbird-project/swift-websocket
server-side-swift swift websocket-client websockets
Last synced: 9 months ago
JSON representation
Support for WebSockets
- Host: GitHub
- URL: https://github.com/hummingbird-project/swift-websocket
- Owner: hummingbird-project
- License: apache-2.0
- Created: 2024-11-12T14:54:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-05T15:38:17.000Z (10 months ago)
- Last Synced: 2025-04-05T16:24:21.395Z (10 months ago)
- Topics: server-side-swift, swift, websocket-client, websockets
- Language: Swift
- Homepage:
- Size: 104 KB
- Stars: 56
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
## swift-websocket
Support for WebSockets
### Overview
Package containing support for WebSockets. It contains three libraries
- WSCore: Core WebSocket handler (can be used by both server and client)
- WSClient: WebSocket client
- WSCompression: WebSocket compression support
### Client
The WebSocketClient is built on top of structured concurrency. When you connect it calls the closure you provide with an inbound stream of frames, a writer to write outbound frames and a context structure. When you exit the closure the client will automatically perform the close handshake for you.
```swift
import WSClient
let ws = WebSocketClient.connect(url: "ws://mywebsocket.com/ws") { inbound, outbound, context in
try await outbound.write(.text("Hello"))
// you can convert the inbound stream of frames into a stream of full messages using `messages(maxSize:)`
for try await frame in inbound.messages(maxSize: 1 << 14) {
context.logger.info(frame)
}
}
```