[[Session inputstream] scheduleinrunloop: [nsunloop currentrunloop]
Formode: nsdefaultrunloopmode];
Because there are transactions to be processed in the main thread, the triggering of peripheral events in the main thread will be blocked. After searching the Forum, there is a post that provides ideas:
"Add the runloopsource of the socket to the runloop of the new thread, and enable the runloop in the new thread"
My understanding is: Create a thread, get its runloop, and then useCodeAdd it so that the callback for receiving data events will not be blocked.
That is, [nsthread detachnewthreadselector: @ select (Act :) totarget: Self withobject: Nil];
[[Session inputstream] scheduleinrunloop: threadrunloop
Formode: nsdefaultrunloopmode];
-(Void) Act :( ID)
{
Threadrunloop = [nsunloop currentrunloop];
If (! Threadshouldexit)
{
[[Nsunloop currentrunloop] runmode: nsdefaultrunloopmode beforedate: limitdate];
}
}
Then, add stream to the runloop of the sub-thread.