Skip to content

Commit

Permalink
Fixed connecting to echo.websocket.org. Needed SNI hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 10, 2024
1 parent 69f44c2 commit d599822
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Snippets/WebSocketClientTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import HummingbirdWSClient
import Logging

var logger = Logger(label: "TestClient")
logger.logLevel = .trace
do {
try await WebSocketClient.connect(
url: .init("https://echo.websocket.org"),
configuration: .init(maxFrameSize: 1 << 16),
logger: logger
) { inbound, outbound, _ in
try await outbound.write(.text("Hello"))
for try await msg in inbound.messages(maxSize: .max) {
print(msg)
}
}
} catch {
logger.error("Error: \(error)")
}
6 changes: 4 additions & 2 deletions Sources/HummingbirdWSClient/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public struct WebSocketClient {
let client = try ClientConnection(
TLSClientChannel(
WebSocketClientChannel(handler: handler, url: url, configuration: self.configuration),
tlsConfiguration: tlsConfiguration
tlsConfiguration: tlsConfiguration,
serverHostname: host
),
address: .hostname(host, port: port),
eventLoopGroup: self.eventLoopGroup,
Expand Down Expand Up @@ -150,7 +151,8 @@ public struct WebSocketClient {
url: url,
configuration: self.configuration
),
tlsConfiguration: TLSConfiguration.makeClientConfiguration()
tlsConfiguration: TLSConfiguration.makeClientConfiguration(),
serverHostname: host
),
address: .hostname(host, port: port),
eventLoopGroup: self.eventLoopGroup,
Expand Down

0 comments on commit d599822

Please sign in to comment.