socketio / socket.io-client-swift

Other
5.22k stars 841 forks source link

Unable to listen to Socket events through Namespace . #965

Closed IOSFreak455 closed 3 years ago

IOSFreak455 commented 6 years ago

Hi @nuclearace,

I am facing with an issue currently, i am able to connect to socket and emit message, but i am unable to listen to socket events ?

// Connecting to Socket

NSURL *url=[NSURL URLWithString:@"https://app.demoSocket.io"];
    socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @YES}];  // In order to check the log
    [socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
    NSLog(@"socket connected ");

// Joining namespace after socket connection

NSString *nameSpaceStr = [NSString stringWithFormat:@"/rt.demoSocket.io/client"];
 [socket joinNamespace:nameSpaceStr];

// Getting User Login Token from Login API

NSString *TokenValue = [[NSUserDefaults standardUserDefaults]
                                stringForKey:@"token"];
NSLog(@"The login token is %@", TokenValue);

// Sending Login Token to Socket Server

NSMutableDictionary *message = [[NSMutableDictionary alloc] init];
        [message setObject:savedTokenValue forKey:@"id"];
        [self.socket emit:@"LoginDetails" with:@[message]];
        NSLog(@"The login details are %@",message);

// Listentng Socket Events

 [self.socket on:@"gettingCallStatus" callback:^(NSArray* data , SocketAckEmitter * ack) {
            NSLog(@"On mesage ack is %@", ack);

I am unable to listen to socket events, could you help me out. Note 1: I am using correct Socket listening Event name .

Note 2: When i am sending/emitting the login token to socket server, my login token is continuously adding to socket sever (by doing this socket server may leads to slow down) . How we can stop this once we have sent the login token .

Waiting for your reply

nuclearace commented 6 years ago

Is your namespace really "/rt.demoSocket.io/client" or should it just be "/client"? Also make sure that you're properly storing the manager.

IOSFreak455 commented 6 years ago

my namespace is " /rt.demoSocket.io/client " only .

nuclearace commented 6 years ago

What do your logs say?

IOSFreak455 commented 6 years ago

I was getting something like this

LOG SocketIOClient: Emitting: 2/rt.demoSocket.io/client,["LoginDetails",{"id":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjU5ZjIzYzNiZjQ4ZTlmNGNlYjYzOWZlNyIsImlhdCI6MTUyMDI1Mjc1N30._wvoRGjv5Im7pNf06_rhi_zWMK2Vy0Wa32LsGegY7HA"}] 2018-03-05 17:56:01.881042+0530 Demo[6456:470489] LOG SocketIOClient: Adding handler for event: gettingCallStatus D31A0DC6-FF07-4E88-BF1C-45F5EB210902 2018-03-05 17:56:01.881112+0530 Demo[6456:471288] LOG SocketEngine: Writing ws: 2/rt.demoSocket.io/client,["setDetails",{"id":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjU5ZjIzYzNiZjQ4ZTlmNGNlYjYzOWZlNyIsImlhdCI6MTUyMDI1Mjc1N30._wvoRGjv5Im7pNf06_rhi_zWMK2Vy0Wa32LsGegY7HA"}] has data: false 2018-03-05 17:56:01.881294+0530 Demo[6456:470489] LOG SocketIOClient: Adding handler for event: auth_success

nuclearace commented 6 years ago

And is your server sending anything? Do you see anything in the logs where the socket/engine is getting things back?

IOSFreak455 commented 6 years ago

No i dn't see anything. Except this thing from socket , once i send the login token to socket through emit message.

2018-03-05 17:56:01.881042+0530 Demo[6456:470489] LOG SocketIOClient: Adding handler for event: gettingCallStatus
D31A0DC6-FF07-4E88-BF1C-45F5EB210902

And moreover, my login token keeps on adding on the server, i can see the logs printing continuously in my Xcode Console . is this the making problem to our listening events .?

Note : When i tested locally i am able to listen to socket events Properly ..

nuclearace commented 6 years ago

Sounds like you have an API issue then, which I can't help with. I can only give some suggestions.

  1. Make sure your manager is a property or it will be release by ARC and nothing will work.
  2. Make sure you have the right namespace. If you use a url like "https://mysocket.url/namespace" in a JS client then the namespace you need in the Swift version is "/namespace".
  3. Make sure you add all handlers before calling connect, or there's no guarantee that they will be called.
  4. Make sure you're sending the right events at the right times.