Hello,
I am trying to use NSURLSessionStreamTask, as on paper, it's supposed to do what I want:
I need a raw TCP/IP connection to a server, where I write raw data and from which I receive similar type of data. The server *does not understand HTTP*.
In my situation, the connection to the server can be behind a proxy, and it seems that on principle, the NSURLSession API is supposed to handle that.
However, from what I have observed using Little Snitch and a local proxy (tinyproxy to be precise), is that NSURLSessionStreamTask-s do not care to know about HTTP(S) proxies. It will, however, use a SOCKS proxy if one is set. But I need to be able to go through the HTTP(S) proxies as well.
I find this highly surprising, as it is absolutely possible to use an HTTP(S) proxy for raw TCP/IP connections, simply by using the HTTP CONNECT method (RFC 2817 <
https://tools.ietf.org/html/rfc2817>)
So I see two possibilities here: either what I am trying to do is just not yet possible with the current APIs, or I am doing something wrong.
For info, my setup is as follows:
- tinyproxy running on 127.0.0.1 on port 8888
- HTTP and HTTPS proxy pointing to tiny.proxy (/etc/host points it to localhost)
- No SOCKS proxy
- Using default NSURLSessionConfiguration
- `connectionProxyDictionary' left to `nil' to use system settings (also tried setting it to the dict from CFNetworkCopySystemProxySettings)
On running the code, I get Little Snitch asking me if my program can access the TCP server, and I see absolutely nothing in tinyproxy's log about any connection request.
What I should see instead is what happens when I do things manually: I should see a connection request in tinyproxy's logs, and Little Snitch should ask me if tinyproxy (not the program) can access the TCP server.
Because the remote TCP server does not understand HTTP at all, I cannot use an NSURLSessionDataTask to then be converted to a stream task.
Any thoughts on what I could do?
Am I doing something wrong or is the API just not capable of doing that yet?
Thanks in advance!