Questions tagged [urlsessionwebsockettask]
13 questions
4
votes
1 answer
URLSessionWebSocketTask: Fatal error: Only one of message or error should be nil
I've been getting this error randomly since I recently used URLSessionWebSocketTask, which causes my program to crash every time:
Fatal error: Only one of message or error should be nil
But I can't find a specific way to reproduce it, because I…

Aofei Sheng
- 121
- 6
3
votes
1 answer
add header to URLSessionWebSocket
I'm working withURLSessionWebSocket to learn more about it.
I'm using this class for it
my question is, how can I add authentication header to it? (Content-Type, ACCOUNT-AUTHORIZATION and SUB-AUTHORIZATION)
thank you so much
lass WebSocketConnector…

Marc t
- 109
- 6
3
votes
0 answers
iOS 13 URLSessionWebSocketTask tries to disconnect twice
I am trying to implement web socket client with the new URLSession web socket support. Here is my simple implementation:
import Foundation
class WebSocketTest: NSObject {
var session: URLSession?
var task: URLSessionWebSocketTask?
…

Mikayel Aghasyan
- 225
- 2
- 11
2
votes
0 answers
URLSessionWebSocketTask fails with invalid response for specific service
I'm currently trying to establish a websocket connection to a Paperless-ngx instance in iOS using URLSessions webSocketTask using the following code:
let wsTask = URLSession.shared.webSocketTask(with: URL(string:…

Leo Klaus
- 73
- 1
- 8
2
votes
0 answers
How to use URLSessionWebSocketTask + URLProtocol properly
Http connection + URLProtocol works fine. But now I try to include websockets in this scheme and it hasn't been working.
Here is websockets level:
var urlSession = URLSession(configuration: myConfiguration, delegate: nil, delegateQueue: .main) …

olle
- 61
- 1
- 1
- 4
2
votes
1 answer
conforming to a protocol require delegate variable be available in ios13
having this protocol
public protocol URLSessionWebSocketTaskProtocol {
func send(_ message: URLSessionWebSocketTask.Message, completionHandler: @escaping (Error?) -> Void)
func receive(completionHandler: @escaping…

Yoel Jimenez del valle
- 1,270
- 1
- 9
- 20
2
votes
1 answer
How to reconnect a URLSessionWebSocketTask once its cancelled?
I am cancelling or disconnecting an active WebSocket task using the following code
socket.cancel(with: .goingAway, reason: nil)
Is there any way to reconnect back or should we create a new URLSessionWebSocketTask and resume again ?

subin272
- 733
- 6
- 24
2
votes
0 answers
Intercept websocket HTTP upgrade request in Ios/Swift 5 - URLProtocol
I'm building a library for redirecting all requests in a whitelist to a different host. There are several examples out there about how to do this so most of the the work on that front is finished. The library makes some modifications to the original…

Tokens94
- 113
- 1
- 8
1
vote
1 answer
iOS Swift WebSocket - Set session data for Vapor server
I am trying to setup server using Vapor. As client, I have simple iOS app using NSUrlSession - URLSessionWebSocketTask. My question is... how I can set session.data from iOS app?
iOS App - Connect method
func connect(completion: @escaping ()->() = {…

George Heints
- 1,303
- 3
- 20
- 37
1
vote
1 answer
Unable to create URLSessionWebSocketTask with background configuration
error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
I'm trying to create URLSessionWebSocketTask…

SPatel
- 4,768
- 4
- 32
- 51
0
votes
0 answers
`try await URLSessionWebSocketTask.send()` does not return nor throw
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…

DeMo
- 47
- 1
- 7
0
votes
1 answer
Why does webSocketTask.receive never complete and how do I force completion in my Swift app?
I have a Swift app that uses a web socket to download stock price information from a public API. I send a message through the socket to subscribe to various stock price changes then wait for a continuous stream of messages to be received but when I…

Stephen501
- 153
- 8
0
votes
1 answer
URLSessionWebSocketTask.receive() doesn't throw on cancel()
I am repeatedly calling URLSessionWebSocketTask.receive. I've tried recursively calling the version with the completion handler, as well as looping over the new async version.
At some point, I'm not receiving any more messages, and I want to cancel…

Ryan Burgoyne
- 76
- 5