1

I have a SocketCommunication class which is created with the following code

CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)host, port, &readStream, &writeStream);
self.inputStream = (__bridge NSInputStream *)readStream;
self.outputStream = (__bridge NSOutputStream *)writeStream;

_inputStream.delegate = self;
_outputStream.delegate = self;

[_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

[_inputStream open];
[_outputStream open];

Everything works fine. But the delegate is called in the UI Thread. The parsing of the data can take some time in some cases.

How can i tell the NSInputStream to call the delegate in a background thread?

Maybe with an own NSRunLoop?

Thomas Geulen
  • 201
  • 5
  • 14
  • 1
    So finally i figured it out. I found the following link and it works for me https://stackoverflow.com/questions/15344400/nsinputstream-stops-running-sometimes-throws-exc-bad-access – Thomas Geulen Aug 09 '13 at 09:26

0 Answers0