Javascript 奇怪的节点js/socket io崩溃?

Javascript 奇怪的节点js/socket io崩溃?,javascript,node.js,socket.io,Javascript,Node.js,Socket.io,我有一个游戏,它的服务器运行在NodeJS上,使用socket io和mysql存储用户数据。问题是我的服务器已经崩溃了两次,它给我的只是以下信息: [36m[game.js][0m [31m[0m [36m[game.js][0m [31m/root/node_modules/socket.io/lib/transports/jsonp-polling.js:88[0m [36m[game.js][0m [31mthis.response.writeHead(200, {[0m [36m[ga

我有一个游戏,它的服务器运行在NodeJS上,使用socket io和mysql存储用户数据。问题是我的服务器已经崩溃了两次,它给我的只是以下信息:

[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m/root/node_modules/socket.io/lib/transports/jsonp-polling.js:88[0m
[36m[game.js][0m [31mthis.response.writeHead(200, {[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31m^[0m
[36m[game.js][0m [31m[0m
[36m[game.js][0m [31mTypeError: Cannot call method 'writeHead' of undefined
at JSONPPolling.doWrite (/root/node_modules/socket.io/lib/transports/jsonp-polling.js:88:17)
at JSONPPolling.write (/root/node_modules/socket.io/lib/transports/http-polling.js:132:8)
at JSONPPolling.packet (/root/node_modules/socket.io/lib/transport.js:515:15)
at JSONPPolling.error (/root/node_modules/socket.io/lib/transport.js:498:8)
at JSONPPolling.onData (/root/node_modules/socket.io/lib/transports/jsonp-polling.js:69:10)
at IncomingMessage.<anonymous> (/root/node_modules/socket.io/lib/transports/http.js:65:12)
at IncomingMessage.emit (events.js:64:17)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:127:21)
at Socket.ondata (http.js:1468:22)
at TCP.onread (net.js:374:27)[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m/root/node_modules/socket.io/lib/transports/jsonp polling.js:88[0m
[36m[game.js][0m[31M此响应.写头(200,{[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31m^[0m
[36m[game.js][0m[31m[0m
[36m[game.js][0m[31mTypeError:无法调用未定义的方法'writeHead'
在JSONPPolling.doWrite(/root/node_modules/socket.io/lib/transports/jsonp polling.js:88:17)
在JSONPPolling.write(/root/node_modules/socket.io/lib/transports/http polling.js:132:8)
在JSONPPolling.packet(/root/node_modules/socket.io/lib/transport.js:515:15)
在JSONPPolling.error(/root/node_modules/socket.io/lib/transport.js:498:8)
在JSONPPolling.onData(/root/node_modules/socket.io/lib/transports/jsonp polling.js:69:10)
输入消息时。(/root/node_modules/socket.io/lib/transports/http.js:65:12)
在IncomingMessage.emit(events.js:64:17)
在HTTPParser.parserOnMessageComplete[作为onMessageComplete](http.js:127:21)
在Socket.ondata(http.js:1468:22)
在TCP.onread(net.js:374:27)[0m

Socket io的响应头似乎有一些问题,但我如何着手解决这个问题?顺便说一句,我还没有尝试过任何东西(因为我真的不知道从哪里开始)

我解决了它,这是Socket.io中jsonpolling的一个错误,只需使用以下命令禁用它:

socket.set('transports', [ 'websocket', 'htmlfile', 'xhr-polling' ])

现在它可以工作了。耶!

你把这一行添加到了什么文件中?在我服务器的js文件的开头(当然是在需要socketio之后)是
io.configure(function(){io.set('transports',['websocket','htmlfile','xhr polling];});
(是的,现在是io.set,我想socket.set不再工作了)