nodejs ws.Server的特定选项

Lum*_*n75 3 javascript websocket node.js

有人可以解释我什么disableHixie,clientTrack在nodejs websocket库'ws'的意思是:

new ws.Server([options], [callback])

options Object
host String
port Number
server http.Server
verifyClient Function
path String
noServer Boolean
disableHixie Boolean
clientTracking Boolean
callback Function
Run Code Online (Sandbox Code Playgroud)

我无法找到结论性的描述意味着什么.

小智 14

Hixie-76是WebSocket支持的旧版和不推荐使用的协议,但该协议仍在某些版本的Safary和Opera中使用.如果为false,则库'ws'中的默认值为false,但您可以禁用该设置并将disableHixie选项设置为true.

clientTracking选项提供存取权限活跃的WebSocket客户的集合.默认值为true.见下文:

var wss = new WebSocketServer({server:app });

wss.on('connection', function (ws) {
   .....
   console.log('Total clients: ', wss.clients.length);
   ....
}
Run Code Online (Sandbox Code Playgroud)

编辑:附加信息:

verifyClient功能允许您添加任何自定义代码来接受或拒绝传入的连接.您的代码收到一个info包含三个成员的对象:

  • info.origin: 连接的起源
  • info.secure: 如果此连接已获得授权或加密,则为True
  • info.req:http.Server此连接的请求对象

verifyClient函数可以采用以下两种形式之一:

var wss1 = new WebSocketServer ({ ..., 
   verifyClient: function(info) {
      # ...check data in info and return true or false...
   }
);

var wss2 = new WebSocketServer ({ ..., 
   verifyClient: function(info, callback){
      # ...check data in info and call
      # callback(true) for success or
      # callback(false) for failure 
   }
});
Run Code Online (Sandbox Code Playgroud)

如果您可以立即验证客户端,则第一种形式更简单.对于异步验证,请使用第二种形式.