nuclearace / Socket.IO-Client-Swift

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

Tried emitting when not connected socket io objective-c #154

Closed mostafatabal closed 6 years ago

mostafatabal commented 6 years ago

@nuclearace I tred to use socket io library but i've problem to emit : this is js code :

var io = require('socket.io')();

io.on('connection', function(socket) {
  console.log('connected!');
  console.log('roomId request: ' + socket.handshake.query.roomId);
  let roomId = socket.handshake.query.roomId;

  socket.on(roomId, function(data) {

    console.log('----------------------------------------------');
    console.log("data: " + JSON.stringify(data));

   socket.emit(roomId,data);
    console.log('----------------------------------------------');
  });

});

io.listen(8080);

and this from code objective-c:-

  NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"];
    SocketManager* manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log" : @YES,@"connectParams":@{@"roomId": self.requestId}}];
    socket = manager.defaultSocket;

    [socket on:@"roomId" callback:^(NSArray* data, SocketAckEmitter* ack) {

      //

    }];
    [socket connect];

and always got this error : - LOG SocketIOClient{/}: Handling event: error with data: ["Tried emitting roomId when not connected"]

please help

nuclearace commented 6 years ago

Wait till you get the "connect" event before emitting anything.

mostafatabal commented 6 years ago

@nuclearace how check if socket is connected , and in server node js console.log('connected!'); that's i connected can you tell me ho do that in objective-c ?