CNode

socket.io中的get和set方法找不到了

Rrebaomi发布于12 年前最后回复12 年前1 回复8860 浏览0 收藏

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

查看回复

回复 (1)

R
rebaomi#1·12 年前

补充:安装socket.io@0.9版本,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官方文档

参与回复
登录后即可参与回复。登录