Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Synchronous SocketIO connection #170

Open
njunghans opened this issue Apr 22, 2014 · 3 comments
Open

Synchronous SocketIO connection #170

njunghans opened this issue Apr 22, 2014 · 3 comments

Comments

@njunghans
Copy link

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.

@njunghans
Copy link
Author

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.

@pkyeck
Copy link
Owner

pkyeck commented Apr 23, 2014

there is a PR for this #169 - will take a look at this

@njunghans
Copy link
Author

Thanks a lot,

I would suggest to implement it in the @protocol SocketIOTransportDelegate 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 !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants