I want to send multiple messages to a web socket like this:
let session = URLSession(configuration: .default)
var socket = session.webSocketTask(with: URLRequest(url: self.url, timeoutInterval: 30)
socket.resume()
do {
for message in messages {
try await socket.send(message)
}
} catch {
print(error)
}
Sometimes all messages are sent, but most times the 10th messages simply does not finish nor fail. I even added delegate methods to detect if the socket is closed or if something failed, but those delegate methods never get called. The send simply does not return nor throw. I thought that adding the timeoutInterval would cause the send to fail if it didn’t succeed after 30 seconds, but that does not seem to be the case.
Has anyone an idea what could be happening here and how I can resolve this? Any help is greatly appreciated, thanks in advance.
PS: the message it failed on mostly is only about 79 Bytes, so it should not take that long to send, especially since sending far longer messages works just fine
EDIT: I just tried to use the synchronous version of send
with the completionHandler
as I hoped that maybe the async version might be bugged, but I have the same problem using that, no completion handler is called