Re: Simple iOS App with Foundation InputStream and OutputStream...


Brandon Peters <bap04e@...>
 

Jens,

Thanks for reply. I thought the +[NSStream getStreamsToHostWithName:…] was deprecated in iOS 11+?

--Brandon

On Nov 15, 2017, at 12:41, Jens Alfke <jens@...> wrote:



On Nov 15, 2017, at 8:25 AM, Brandon Peters <bap04e@...> wrote:

All,

I created a simple iOS app to connect to a server and receive a message. I am doing this as an example app using InputStream, OutputStream, and StreamDelegate.

Consider using NSURLSessionStreamTask; it’s higher-level with IMHO a better API, and it supports proxies.

The Server is a simple Java app running on my MacBook Pro. The iOS app is running on my iPhone 7. I use the address of my laptop on the local network and the port the Java app is listening on (xxx.xxx.xxx.xxx:ppppp) in the URL object. Despite this, my InputStream and OutputStream objects are nil after calling their initializers.

If you’re using an NSURL for this, I don’t think you’re doing it correctly. URLs have schemes, which identify what protocol to use. Since you’re just making a raw TCP connection you don’t have a defined protocol that NSURL knows about.

The API for creating raw NSStreams for a TCP client connection is +[NSStream getStreamsToHostWithName:…].

—Jens




Join {cocoa@apple-dev.groups.io to automatically receive all group messages.