views:

41

answers:

0

I am new to cocoa and in my cocoa application, I'm trying to create the websocket in a new thread but it is not working. I'm doing the following when initializing mySocket class,

 NSThread *thread = [[NSThread alloc]
          initWithTarget:self selector:@selector(runEventLoop) object:nil];  
    [thread start];

....

- (void) runEventLoop
{
 NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];

  while (YES)
 {
   [[NSRunLoop currentRunLoop] runMode:NSRunLoopCommonModes beforeDate:
                               [NSDate dateWithTimeIntervalSinceNow:30]];

 }
 [innerPool release];
}

... then when trying to open the socket,

   socket = [[AsyncSocket alloc] initWithDelegate:self];
   [socket setRunLoopModes:[NSArray arrayWithObjects:NSRunLoopCommonModes, nil]];
   [socket connectToHost:url.host onPort:[url.port intValue] withTimeout:5000 error:nil];

However, connectToHost is returning YES but the timeout is happening immediately. So, I'm pretty sure I'm messing up badly with NSRunLoopCommonModes.

Can someone tell me how to about this issue?