Socket.IO-Client-Swift icon indicating copy to clipboard operation
Socket.IO-Client-Swift copied to clipboard

Socket On Method not getting called

Open amrit42087 opened this issue 9 years ago • 8 comments

Hi I am using Objective-C for my project. The socket is getting connected. I am initialising the Socket Object like this. socket = [[SocketIOClient alloc] initWithSocketURL:url options:@{@"log": @YES, @"forcePolling": @YES}]; I am calling the emit method method after getting connected. But the Socket On method is not getting called.

This is the code that I am using.

[socket on:@"xxxx:chat" callback:^(NSArray data, SocketAckEmitter ack) { NSLog(@"Data--%@",data); }]; [socket on:@"connect" callback:^(NSArray data, SocketAckEmitter ack) { NSLog(@"socket connected--%ld",(long)[socket status]); [socket emit:@"xxxx:chat" withItems:@[@{@"sender_id":@"57307868bbe22c8363cc059e",@"to_id":@"573079babbe22c8363cc059f",@"msg":@" Message"}]]; }];

amrit42087 avatar Jun 09 '16 10:06 amrit42087

Is the socket a property or a local variable? If it's a local variable you're doing it wrong, since it'll be released once it goes out of scope.

nuclearace avatar Jun 09 '16 13:06 nuclearace

Its a Property.

amrit42087 avatar Jun 09 '16 13:06 amrit42087

@property (strong,nonatomic) SocketIOClient* socket;

amrit42087 avatar Jun 09 '16 13:06 amrit42087

It looks like you're expecting to get the same event that you're sending? Is that the correct API? If it is you should make sure your server is configured properly

nuclearace avatar Jun 09 '16 13:06 nuclearace

The server is configured properly as everything works fine on Android. The same URL works fine.

amrit42087 avatar Jun 10 '16 04:06 amrit42087

Do you see your event getting to the engine in your logs?

nuclearace avatar Jun 10 '16 05:06 nuclearace

Yes message is received at the backend.

amrit42087 avatar Jun 10 '16 06:06 amrit42087

I meant from the client's engine log. It would look something like LOG SocketEngine: Got message: 451-["multipleItems",[1,2],{"test":"bob"},25,"polo",{"_placeholder":true,"num":0}]

nuclearace avatar Jun 10 '16 13:06 nuclearace