while(1) block my recv thread

Posted by zp26 on Stack Overflow See other posts from Stack Overflow or by zp26
Published on 2010-04-15T15:12:29Z Indexed on 2010/04/15 20:53 UTC
Read the original article Hit count: 462

Filed under:
|
|
|
|

Hello. I have a problem with this code. As you can see a launch with an internal thread recv so that the program is blocked pending a given but will continue its execution, leaving the task to lock the thread. My program would continue to receive the recv data socket new_sd and so I entered an infinite loop (the commented code). The problem is that by entering the while (1) my program block before recv, but not inserting it correctly receives a string, but after that stop. Someone could help me make my recv always waiting for information? Thanks in advance for your help.

-(IBAction)Chat{

      [NSThread detachNewThreadSelector:@selector(riceviDatiServer) toTarget:self withObject:nil];  

}

-(void)riceviDatiServer{

 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

 labelRicevuti.text = [[NSString alloc] initWithFormat:@"In attesa di ricevere i dati"];

 char datiRicevuti[500];
 int ricevuti;

    //while(1){
 ricevuti = recv(new_sd, &datiRicevuti, 500, 0);

 labelRicevuti.text = [[NSString alloc] initWithFormat:@"%s", datiRicevuti];
    //}

 [pool release];

}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about threads