title: iOS 13 URLSessionWebSocketTask Current Connection Status
body: <p>I have my <code>URLSessionWebSocketDelegate</code> set up and implemented </p>
  
  <pre><code>urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?)
  </code></pre>
  
  <p>However, it only seems to hit the delegate if the server makes a proper disconnect. If the connection drops or the server doesn't provide a disconnect code, the delegate function never runs. I've also tried checking the <code>URLSessionWebSocketTask</code> properties <code>closeCode</code> and <code>closeReason</code> before and after the disconnect and they don't change unless the server sends a proper disconnect code.</p>
  
  <p>While I have control over the server and can be sure intentional disconnects have a code, what happens if the network connection dies? Or if the server goes down? I would assume the delegate function <em>should</em> still get called.</p>
  
  <p>What's interesting is that my listening function gets an error and the error states the following: </p>
  
  <pre><code>Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSErrorFailingURLStringKey=[urlomitted], NSErrorFailingURLKey=[urlomitted]
  </code></pre>
  
  <p>So while I COULD manually disconnect the socket if I see error 57, I don't know if that's comprehensive for all the different variations of disconnect.</p>
  
  <p>I think I'm either doing something wrong or it's a bug, but I can't find anyone else with the same issue, so I thought I'd ask before submitting a radar.</p>