Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mostafatabal opened this issue Jan 19, 2018 · 2 comments
Closed

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

mostafatabal opened this issue Jan 19, 2018 · 2 comments

Comments

@mostafatabal
Copy link

@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
Copy link
Owner

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

@mostafatabal
Copy link
Author

@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 ?

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

No branches or pull requests

2 participants