-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fatalError when trying to send a message using URLSessionWebSocketTask #4730
Comments
I'm having this same problem |
I've been having issues with import Foundation
// Import URL Session on Linux:
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
@main
public struct Test {
public private(set) var text = "Hello, World!"
public static func main() async throws {
let ws = URLSession.shared.webSocketTask(with: URL(string: "wss://gateway.discord.gg/?v=10&encoding=json")!)
ws.resume()
_ = try await ws.receive()
}
} And:
Specifically on Linux--no errors if run from Xcode/on macOS. |
Yup, I didn't even think to test receive() since Twitch doesn't send anything without the client authenticating explicitly with NICK + PASS, but I can confirm this is also the case for me. Updated the main issue as well to reflect that. Only an issue on Linux, using macOS everything works as expected. |
This is still happening on the official swift:5.8 release image. |
To be honest it seems the WebSocket implementation can never work, as And if I am not mistaken, that's what is checked here in CFURLSessionInterface.c Boolean CFURLSessionWebSocketsSupported(void) {
curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
for (int i = 0; ; i++) {
const char * const protocol = info->protocols[i];
if (protocol == NULL) {
break;
}
if ((0 == strncmp(protocol, "ws", 2)) ||
(0 == strncmp(protocol, "wss", 3))) {
return true;
}
}
return false;
} But maybe I am just holding it wrong™ 🤷♂️ |
You are holding it right :( |
Just for reference: Even when compiling
Even if the support is experimental in curl, this is maybe actionable by the team here? |
Hey, I am trying to get a WebSocket connection running on Linux using FoundationNetworking, I am using the nightly-5.8-jammy docker image inside of a devcontainer:
Everything compiles correctly but when I try to actually send a message (UPDATE: also happens when calling
receive()
), I get a fatalError, saying that the URL is invalid:I attempt to connect to Twitch Chat, I've made a very simple test that just tries to send a single message to their server:
That code runs perfectly fine under macOS (using Swift 5.7), but as soon as it's run on Linux I get the error from above.
I've tried using different WebSocket URLs, but everything yields the same result.
The text was updated successfully, but these errors were encountered: