1

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];
}
Milad Rezazadeh
  • 1,473
  • 12
  • 34
  • 1
    You've posted the code that has nothing to do with your streaming. BTW your threadLock has no effect at all cause you're creating the new one for each thread. And even more - it is leaking, cause you don't release it. – Max Dec 24 '11 at 11:29
  • thank you , so what you need I post for you , about the lock I understand it now. – Milad Rezazadeh Dec 30 '11 at 19:10

1 Answers1

1

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

Milianoo
  • 1,476
  • 1
  • 10
  • 9