require('socket.io')
httpServer
(http.server) 要绑定到服务器options
(Object)path
/socket.io
serverClinet
true
origins
*
pingTimeout
5000
pingInterval
25000
upgradeTimeout
10000
maxHttpBufferSize
10e7
allowRequest
fn(err,success)
,其中success
是一个布尔值,false表示请求被拒绝,err是一个错误代码。transports
['polling','websocket']
allowUpgraders
true
cookie
io
false
不发送。cookiePath
/
cookie
选项的路径。如果为false,则不会发送路径,这意味着浏览器将只在engine.io附加路径(/engine.io
)上发送cookie。设置为“假”不在所有请求上保存IO cookie。cookieHttpOnly
true
true
httponly IO cookie。如果cookie
或cookiepath
,设置为false,则此选项无效。pingTimeout
和pingInterval
参数将影响socket知道服务器不再可用之前的延迟。例如,如果底层TCP连接由于网络问题而未正确关闭,则客户端可能需要等待pingTimeout+pingInterval
毫秒,然后才能获得disconect
(断开连接)事件。transports
数组的顺序很重要。默认情况下,首先建立一个长轮询连接,然后在可能的情况下升级到WebSocket。使用['websocket']
意味着如果无法打开websocket连接,就不会有回退。