• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using NSURLSessionStreamTask for WebSockets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using NSURLSessionStreamTask for WebSockets


  • Subject: Using NSURLSessionStreamTask for WebSockets
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 14 Mar 2017 15:36:03 -0700

So I’ve been hoping that NSURLSessionStreamTask would make it easier to implement WebSockets by allowing me to make the initial HTTP handshake as a regular HTTP request with an NSURLSessionDataTask, then switch to a raw stream by returning NSURLSessionResponseBecomeStream from the response delegate method.

I just tried it (on macOS 10.12.4 beta 4) and unfortunately it doesn’t work. Upgrading protocols requires that the value of the request's “Connection:” header be “Upgrade", but the value gets changed to “keep-alive” when sent, causing the server to reject the request. I assume this is one of those headers that the client can’t control. :(

I can instead create the task as a stream from the beginning by calling -streamTaskWithHostName:port:. But then I’m basically working with raw TCP, so I need to construct and parse the HTTP messages myself, and more importantly, I lose SSL support and the semi-automatic handling of proxies, redirects and auth challenges. (It’s really no better than NSStream.)

Is this something that could be fixed in the future, or is it considered a non-feature for NSURLSession to allow HTTP connection upgrades?

—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Using NSURLSessionStreamTask for WebSockets
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
    • Re: Using NSURLSessionStreamTask for WebSockets
      • From: Jens Alfke <email@hidden>
    • Re: Using NSURLSessionStreamTask for WebSockets
      • From: Thibault Martin-Lagardette <email@hidden>
  • Prev by Date: AVAssetDownloadURLSession development
  • Next by Date: Re: Using NSURLSessionStreamTask for WebSockets
  • Previous by thread: AVAssetDownloadURLSession development
  • Next by thread: Re: Using NSURLSessionStreamTask for WebSockets
  • Index(es):
    • Date
    • Thread