socket.IO-objc
socket.IO-objc copied to clipboard
Synchronous SocketIO connection
Hi,
I am trying to create a synchronous connection with NSCondition. But when i wait for the signal, the socket calls onDisconnect(); right after a successful connection. I even tried with a sleep(1); and got the same behavior. The connection is not even opened in the same thread as the sleep. Did i missed something ? Is there a way to ensure the connection to go through ?
Thanks a lot.
Ok, i was completely wrong. This has nothing to do with threads.
I am actually receiving this error because i am using a custom resourceName, and in SocketIOTransportWebsocket and SocketIOTransportXHR there is no custom resourceName possible. Causing the disconnect without error.
there is a PR for this #169 - will take a look at this
Thanks a lot,
I would suggest to implement it in the @protocol SocketIOTransportDelegate <NSObject> next to host,port and sid ;)
I still have a question for my NSCondition problem though.
-(OperationResult *)OpenConnection{
[socketIOClient setUseSecure:NO];
[socketIOClient setResourceName:@"NotificationService/socket.io"];
[socketIOClient connectToHost:[configuration.ServiceBaseAddress host] onPort:port];
if([openResetEvent waitForSignal:((NSInteger)configuration.ServiceRequestTimeoutInMilliseconds/1000)]){
[self ForceCloseConnection];
OperationResult* res=[[OperationResult alloc] init];
res.ErrorCode=OperationResultCodeServiceNotReachable;
res.ErrorMessage=@"Could not open Connection. Reached timeout.";
return res;
}
ConnectionStateType=ConnectionStateTypeConnected;
return [[OperationResult alloc] initWithResult:nil];
}
-(void)socketIODidConnect:(SocketIO *)socket{
[openResetEvent signal];
}
I want to wait until the event is fired in the connection method, but the thread is locked and the client can only connect after the NSCondition timed out. (openResetEvent is my NSCondition handler)
Do you have an idea to overcome this ?
Thanks a lot !