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!
wait for the
delegate to be called and add your
sendEvent:
code there. e.g.:this should work.