nuclearace / Socket.IO-Client-Swift

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

Socket On Method not getting called #127

Open amrit42087 opened 8 years ago

amrit42087 commented 8 years ago

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"}]]; }];

nuclearace commented 8 years ago

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.

amrit42087 commented 8 years ago

Its a Property.

amrit42087 commented 8 years ago

@property (strong,nonatomic) SocketIOClient* socket;

nuclearace commented 8 years ago

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

amrit42087 commented 8 years ago

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

nuclearace commented 8 years ago

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

amrit42087 commented 8 years ago

Yes message is received at the backend.

nuclearace commented 8 years ago

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}]