I did not find any decent documentation that explains the streaming process for NSStream. To be specific, release NSInputStream. Threading in Objective-C is currently a mystery to me, simply because it seems so simple.
What is my question related to this particular line:
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
You can specify a run cycle in which the input will run, which I thought was pretty cool. The fact is, if I want input and output streams to run in their own streams, and both instances are created in the same class, say Connection, then how do you run them in your streams?
I ask because delegates. We would have done before [inputStream setDelegate:self], which means that we must declare stream:handleEventto process incoming / outgoing data.
So, ultimately, my question is, if you have one class that sets up an input and output stream, how do you both execute the stream of each stream and delegate responsibility for handling stream events in the current class?
Here is some code for chomp:
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
I think the following:
- You cannot delegate responsibility for both threads in the current class, you will have to delegate separate objects.
- Will one thread work for both threads? (I personally donβt think so, because I / O will be done at the same time)
- I think this is wrong and you can create a separate loop cycle and call scheduleRunLoop against some separate thread?
Any ideas?