I am working on streaming part of application. I needed to put streaming process on the background thread that it uses NSinputstream and NSOutputstream . then I send http commands over this streaming channel on the same thread. I receive the NSStreamEventOpenCompleted and NSStreamEventHasSpaceAvailable and also I receive the http request on the server side , but it doesn't raise the EVENT HAS BYTES AVAILABLE . and I can not receive the responses ... I dont know what is the problem . here is some part of my codes :

Thread that I am using :

- (void)backgroundThread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSLock *threadLock = [[NSLock alloc] init];
while (quitProcess)
{
    if (queue.count > 0)
    {
        [threadLock lock];// Blocks other threads
        cmdQueue = [queue copy];
        [queue removeAllObjects];
        [threadLock unlock];
    }
    else
    {
        sleep(1);
    }

    if (cmdQueue){
        for (NSString* cmd in cmdQueue) 
        {

            if ([cmd isEqualToString:@"subscribe"]){
                [self openCmdLine];
            }else if ([cmd isEqualToString:@"dataConnect"]){
                [self dataConnect];
            }else if ([cmd isEqualToString:@"openCmdLine"]){
                [self openCmdLine];
            }else if ([cmd isEqualToString:@"closeCmdLine"]){
                [self closeCmdLine];
            }else if ([cmd isEqualToString:@"handshake"]){
                sleep(5);
                [self cmdHandshake];
            }else if ([cmd isEqualToString:@"topvol"]){
                [self cmdTopVol];
            }else{
                //subscribe or unsubscribe

            }

        }
        cmdQueue = nil;
    }


   }
   [pool drain];
}
有帮助吗?

解决方案

the reason is because of NSRunloop , that is responsible for connection call back, you should place it in your code

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top