ios - How to properly open and close a NSStream on another thread -


i have application connects server using nsstream on thread. application closes connection should user decide log out. problem never able close stream or thread upon having user disconnect. below code sample on how approach creating thread network , trying close stream:

+ (nsthread*)networkthread {     static nsthread *networkthread = nil;     static dispatch_once_t oncetoken;     dispatch_once(&oncetoken, ^{         networkthread = [[nsthread alloc] initwithtarget:self selector:@selector(networkthreadmain:) object:nil];          [networkthread start];     });      return networkthread; }  + (void)networkthreadmain:(id)sender {     while (yes)     {         @autoreleasepool {             [[nsrunloop currentrunloop] run];         }     } }  - (void)scheduleinthread:(id)sender {     [inputstream scheduleinrunloop:[nsrunloop currentrunloop] formode:nsrunloopcommonmodes];     [inputstream open]; }  - (void)closethread {         [inputstream close];     [inputstream removefromrunloop:[nsrunloop currentrunloop] formode:nsrunloopcommonmodes];     [inputstream release];     inputstream = nil; } 

call made when trying connect inputstream:

[self performselector:@selector(scheduleinthread:) onthread:[[self class] networkthread] withobject:nil waituntildone:yes]; 

any advice appreciated.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -