socket.io中的get和set方法找不到了
发布于 8个月前 作者 rebaomi 716 次浏览

socket.io中的set和get方法没有了,是什么情况

1 回复

补充:安装[email protected]版本,1.0版本中去掉了get和set方法,外加一个:nodejs + socket.io + redis 新手上路http://www.cnblogs.com/aibo/p/3366925.html


自问自答吧,找到答案了,在官方文档里,被《nodejs高级编程》这本书坑了啊,都过时了。。:

The old io.set() and io.get() methods are deprecated and only supported for backwards compatibility. Here is a translation of an old authorization example into middleware-style.

io.set('authorization’, function (handshakeData, callback) { // make sure the handshake data looks good callback(null, true); // error first, ‘authorized’ boolean second }); vs.

io.use(function(socket, next) { var handshakeData = socket.request; // make sure the handshake data looks good as before // if error do this: // next(new Error(‘not authorized’); // else just call next next(); });

socket.io官方文档

回到顶部