Socket.io-client-swift: WebSocket connection drops right away

Created on 26 Feb 2016  ·  4Comments  ·  Source: socketio/socket.io-client-swift

in Obj-C:

    NSURL* url = [[NSURL alloc] initWithString:@"https://api.kubi.me:3000"];
    SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:url options:@{@"forceWebsockets": @YES, @"forcePolling": @NO, @"log": @YES}];

    [socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
        NSLog(@"socket connected");
    }];

    [socket on:@"command-send" callback:^(NSArray* data, SocketAckEmitter* ack) {
        NSLog(@"SOCKET IO!!!");
    }];

    [socket on:@"message" callback:^(NSArray* data, SocketAckEmitter* ack) {
        NSLog(@"SOCKET IO!!!");
    }];

    [socket connect];

server app.js:

io.sockets.on('connection',function(socket){
    console.log('['+Date.now()/1000+'] Socket connected:    ' + socket.id + ' ('+ socket.client.conn.transport.constr$

    socket.on('channel',function(ch){
        socket.join(ch);
    });

    socket.on('disconnect',function(){
        console.log('['+Date.now()/1000+'] Socket disconnected: ' + socket.id + ' ('+ socket.client.conn.transport.co$
    });

    socket.on('command-request', function() {
        io.emit('command-send');
        console.log('Got a command request');

    });
});

NSLog output:

2016-02-25 17:38:28.309 KubiDeviceSDKTestApp[5036:2357257] LOG SocketIOClient: Adding handler for event: connect
2016-02-25 17:38:28.310 KubiDeviceSDKTestApp[5036:2357257] LOG SocketIOClient: Adding handler for event: command-send
2016-02-25 17:38:28.310 KubiDeviceSDKTestApp[5036:2357257] LOG SocketIOClient: Adding handler for event: message
2016-02-25 17:38:28.310 KubiDeviceSDKTestApp[5036:2357257] LOG SocketIOClient: Adding engine
2016-02-25 17:38:28.313 KubiDeviceSDKTestApp[5036:2357257] LOG SocketEngine: Starting engine
2016-02-25 17:38:28.313 KubiDeviceSDKTestApp[5036:2357257] LOG SocketEngine: Handshaking
2016-02-25 17:38:28.319 KubiDeviceSDKTestApp[5036:2357257] LOG SocketIOClient: Client is being released
2016-02-25 17:38:28.320 KubiDeviceSDKTestApp[5036:2357257] LOG SocketEngine: Engine is being closed.
2016-02-25 17:38:28.320 KubiDeviceSDKTestApp[5036:2357257] LOG SocketEngine: Sending ws:  as type: 1
2016-02-25 17:38:28.321 KubiDeviceSDKTestApp[5036:2357257] LOG SocketEngine: Engine is being released

Server app.js console.log output:

[1456450815.4] Socket connected:    /#ZOs-ug3RuSqb0w1eAAAK (WebSocket)
[1456450815.405] Socket disconnected: /#ZOs-ug3RuSqb0w1eAAAK (WebSocket)

Somewhat stuck here and I'm not sure how to get any more logs about errors or what might be happening here...

Most helpful comment

99% sure it's because your socket isn't a property and is thus being released by ARC.

All 4 comments

99% sure it's because your socket isn't a property and is thus being released by ARC.

ah yes.. the n00bz...

iOS beginner here. If anyone can explain the solution, it will be really helpful.

@mayuroks If it's the same issue as this one, you should read up on ARC.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

roma86 picture roma86  ·  4Comments

Dohab picture Dohab  ·  4Comments

huangxiaolin0425 picture huangxiaolin0425  ·  6Comments

Seonift picture Seonift  ·  4Comments

matthiasp42 picture matthiasp42  ·  3Comments