I’ve moved your question over to Core OS > Networking because this is more about networking than about Swift.There’s more than one issue here. guywithmazda spotted one, which is cool because I probably wouldn’t have spotted it myself. OTOH, I have a few more comments which I’ll outline below.First, code like this:while (self.inputStream!.hasBytesAvailable) { … }is incorrect. It’ll probably work but it’s not how you’re supposed to use NSStream. Rather, when you get a .HasBytesAvailable event, you should do one read, process those bytes, and then return. Continuing to work while the -hasXxxAvailable returns true can cause subtle problems. For example: On a fast network you can end up ‘stuck’ in your stream event handler, which prevents anything else on that thread doing any work (which is bad if it’s the main thread). This can happen on both the send and receive sides.On the send side, you end up being incompatible with TCP_NOTSENT_LOWAT. See WWDC 2015 Session 719 Your App and Next Generation Networks.Your d
Topic:
App & System Services
SubTopic:
Networking
Tags: