我有一个游戏,其服务器在节点js上运行,使用socket io和mysql来存储userdata。问题是我的服务器已经崩溃了两次,它给我的全部内容如下:
[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
Socket io似乎对响应的头部有一些问题,但我该怎么做呢?我还没有尝试任何东西(因为我真的不知道从哪里开始)
答案 0 :(得分:2)
我修复了它,这是socket.io中jsonpolling的一个错误,只需用以下命令禁用它:
socket.set('transports', [ 'websocket', 'htmlfile', 'xhr-polling' ])
现在它有效。耶!