Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace(nsp) format is wrong #41

Closed
k7 opened this issue Apr 2, 2015 · 4 comments
Closed

namespace(nsp) format is wrong #41

k7 opened this issue Apr 2, 2015 · 4 comments

Comments

@k7
Copy link

k7 commented Apr 2, 2015

Thank you all guys contributed this awesome project. but there is some thing seems not right.

we should send namespace like this: 0/chat
but in joinNamespace() self.engine?.send("0/\(self.nsp!)")
and it will be 0//chat, the server will complain it.

@nuclearace
Copy link
Member

Don't add the first slash to the option

@nuclearace nuclearace reopened this Apr 2, 2015
@nuclearace
Copy link
Member

It should never get to the engine prepended with a slash. Unless you do something stupid like ["nsp": "//chat"] In which case I'd say your code is broken.

https://github.com/socketio/socket.io-client-swift/blob/master/SwiftIO/SocketIOClient.swift#L107

@k7
Copy link
Author

k7 commented Apr 2, 2015

we should use var opts = ["nsp": "/chat"]
or else the socket.io server will give no socket for namespace undefined

Client.prototype.ondecoded = function(packet) {
  if (parser.CONNECT == packet.type) {
    this.connect(packet.nsp);
  } else {
    var socket = this.nsps[packet.nsp];
    if (socket) {
      socket.onpacket(packet);
    } else {
      debug('no socket for namespace %s', packet.nsp);
    }
  }
};

ps: I have updated the latest repo code.

@k7
Copy link
Author

k7 commented Apr 2, 2015

Now I know why.
I have sent the wrong args in emit and the server parser error
in client

self.socket.emit("authentication", "{\"token\":\"\(token)\"}")

in server

// socket.io-parser 
// index.js

function decodeString(str) {
...
  // look up json data
  if (str.charAt(++i)) {
    try {
      var a = str.substr(i)
      p.data = json.parse(a);
    } catch(e){
      return error();
    }
  }
...
}

@k7 k7 closed this as completed Apr 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants