pkyeck socket.IO-objc not sending event to socket.io server

1.5k views Asked by At

I am using the socket.IO-objc library (https://github.com/pkyeck/socket.IO-objc) in combination with a node server running socket.io, and while I am able to get my iOS client to connect to the server, I can't seem to trigger the message event on the server using the objective-c api. Here is my obj-c code:

     - (void)viewDidLoad
    {
       [super viewDidLoad];

       SocketIO *socketIO = [[SocketIO alloc] initWithDelegate:self];
       [socketIO connectToHost:@"my_ip_address" onPort:8080];
       [socketIO sendEvent:@"message" withData:@"hello"];

and my server code:

io.sockets.on('connection', function (socket) {

    console.log("connect to socket!");

  socket.on('message', function (data) {
    console.log("got some data!");
  });

});

can anyone explain why the server is not receiving the message event? Thanks!

1

There are 1 answers

0
Philipp Kyeck On

wait for the

- (void) socketIODidConnect:(SocketIO *)socket
{
    NSLog(@"socket.io connected.");
}

delegate to be called and add your sendEvent: code there. e.g.:

- (void) socketIODidConnect:(SocketIO *)socket
{
    NSLog(@"socket.io connected.");
    [socketIO sendEvent:@"message" withData:@"hello"];
}

this should work.