How to properly open and close a NSStream on another thread
问题 I have an application that connects to a server using NSStream on another thread. The application also closes the connection should the user decide to log out. The problem is that I am never able to successfully close the stream or the thread upon having the user disconnect. Below is my code sample on how I approach creating a thread for my network and trying to close the stream: + (NSThread*)networkThread { static NSThread *networkThread = nil; static dispatch_once_t onceToken; dispatch_once