nuclearace / Socket.IO-Client-Swift

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

Couldn't call event to Emit #159

Closed mostafatabal closed 6 years ago

mostafatabal commented 6 years ago

@nuclearace

i do everything well but after i added handlers and add socket connect , not call event to go inside to emit message what is the wrong of my code ??

my Server js :-

var io = require('socket.io')();
io.on('connection', function(client) {  
    console.log('Client connected...');

    client.on('join', function(data) {
        console.log(data);
    client.emit('join','Hello from Server');
    });
});
io.listen(4200);  

my client in ios :-

 NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:4200"];
    SocketManager* manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @YES, @"compress": @YES}];
   socket = manager.defaultSocket;

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

    [socket on:@"join" callback:^(NSArray* data, SocketAckEmitter* ack) {
        [socket emit:@"join" with:@[@{@"amount": @"Hello"}]];
    }];

    [socket connect];

and the log from Xcode :-

2018-01-20 11:46:29.417182+0300 Etmam[98823:5787042] LOG SocketIOClient{/}: Adding handler for event: connect
2018-01-20 11:46:29.702365+0300 Etmam[98823:5787042] LOG SocketIOClient{/}: Adding handler for event: join
2018-01-20 11:46:32.903281+0300 Etmam[98823:5787042] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting]
2018-01-20 11:46:32.903641+0300 Etmam[98823:5787042] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2018-01-20 11:46:32.903781+0300 Etmam[98823:5787042] LOG SocketManager: Adding engine
2018-01-20 11:46:33.281828+0300 Etmam[98823:5787278] LOG SocketEngine: Starting engine. Server: http://localhost:4200
2018-01-20 11:46:33.286174+0300 Etmam[98823:5787278] LOG SocketEngine: Handshaking
2018-01-20 11:46:36.748754+0300 Etmam[98823:5787278] LOG SocketEnginePolling: Doing polling GET http://localhost:4200/socket.io/?transport=polling&b64=1
2018-01-20 11:46:59.109582+0300 Etmam[98823:5787042] LOG SocketManager: Manager is being released
2018-01-20 11:46:59.151925+0300 Etmam[98823:5787855] LOG SocketEnginePolling: Got polling response
2018-01-20 11:46:59.152162+0300 Etmam[98823:5787855] LOG SocketEnginePolling: Got poll message: 97:0{"sid":"YroRxsE8T_ZWbhsqAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}2:40
2018-01-20 11:46:59.152509+0300 Etmam[98823:5787855] LOG SocketEngine: Got message: 0{"sid":"YroRxsE8T_ZWbhsqAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
2018-01-20 11:46:59.155039+0300 Etmam[98823:5787855] LOG SocketEngine: Got message: 40
2018-01-20 11:46:59.155518+0300 Etmam[98823:5787855] LOG SocketEngine: Writing poll:  has data: false
2018-01-20 11:46:59.155842+0300 Etmam[98823:5787855] LOG SocketEnginePolling: Sending poll:  as type: 2
2018-01-20 11:46:59.156248+0300 Etmam[98823:5787855] LOG SocketEnginePolling: Created POST string: 1:2
2018-01-20 11:46:59.156824+0300 Etmam[98823:5787855] LOG SocketEnginePolling: POSTing
2018-01-20 11:46:59.157176+0300 Etmam[98823:5787855] LOG SocketEngine: Engine is being released