I want to parse a requested url. When I used websocket.io I had a request-object I could parse. How can I do it with socket.io ?
example:
http://localhost:4000/foo
how can I get out "foo"? I tried:
io.sockets.on('connection', function (socket) {
console.log(socket.handshake.address.address);
console.log(socket.handshake.url);
}
but it does not print "foo"
BTW--Your approach is correct if you are supplying parameters to the socketio connection instead of path elements. It solved my problem when using https://github.com/pkyeck/socket.IO-objc with nodejs socketio to add params to my socket connection.
For example:
[socketIO connectToHost:@"localhost" onPort:8888 withParams:[NSDictionary dictionaryWithObject:@"52523f26f5b23538f000001c" forKey:@"player"]];
constructs URL as follows:
http://localhost:8888/socket.io/1/?t=16807&player=52523f26f5b23538f000001c
The params are accessible on the server in socket.handshake.query
socketio.listen(server).on('connection', function(socket) {
console.log('socket info = ', socket.handshake.query.player);