nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Strange bug (version 5.4.1) #107

Closed lucianocn closed 8 years ago

lucianocn commented 8 years ago

Hi, Debugging with the server log I discovered that when the socket connects, most of time the emit joinRoom is being sent but rarely not (randomly).

I would like to know if there is any problem in my code, or it could be something related to the lib?

NSURL* url = [[NSURL alloc] initWithString:SERVER_SOCKETIO_URL];
SocketIOClient *socket = [[SocketIOClient alloc] initWithSocketURL:url options:nil];

[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
    NSLog(@"SocketIO: Connected.");

    NSLog(@"SocketIO: Joining room %@.", [Authenticator getUnitID]);
    [socket emit:@"joinRoom" withItems:@[@{@"room": @"14"}]];
}];

Thanks,

lucianocn commented 8 years ago

Just adding a NSThread sleepForTimeInterval, before the emit, it got working properly now. Any ideas?

NSURL* url = [[NSURL alloc] initWithString:SERVER_SOCKETIO_URL];
SocketIOClient *socket = [[SocketIOClient alloc] initWithSocketURL:url options:nil];

[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
    NSLog(@"SocketIO: Connected.");

    [NSThread sleepForTimeInterval:1.0];
    NSLog(@"SocketIO: Joining room %@.", [Authenticator getUnitID]);
    [socket emit:@"joinRoom" withItems:@[@{@"room": @"14"}]];
}];