Where to Delegate for StreamDelegate?


Brandon Peters <bap04e@...>
 

All,


I sort of came down with "paralysis analysis" last night. I am developing a small chat app on iOS. I am going to use Foundation's InputStream, OutputStream, and StreamDelegate. I became stuck between these design choices:


  • Apply the StreamDelegate protocol to the chat view controller class.
  • Create a "network manager" singleton class, and apply the StreamDelegate to this class.

Which of these is the "best". Are there any alternatives I am not considering?


 

On Nov 28, 2017, at 7:26 AM, Brandon Peters <bap04e@my.fsu.edu> wrote:

• Apply the StreamDelegate protocol to the chat view controller class.
This is too low level a task for the view controller to be handling.

• Create a "network manager" singleton class, and apply the StreamDelegate to this class.
That’s more reasonable, though there’s no reason this has to be a singleton, and “Connection” might be a better class name. Calling something a “Manager” is often an indication that you haven’t fully thought through what it’s for :)

(At a higher level: unless you’re doing this explicitly for education, it’s kind of painful to implement a network protocol at the raw-byte-stream level. I would recommend at least building on top of a WebSocket library, which will save you a lot of problems dealing with message framing, flow control, SSL, proxy support, and so on.)

—Jens