错误
当用户打开http://sync.aws.af.cm/时,Google Chrome JavaScript 控制台会显示(几秒钟内):
Unexpected response code: 502 error
即使在用户刷新页面后,应用程序也应该记住文本区域的内容。该应用程序在本地运行,但当我将其上传到 AppFog 时无法运行,我怀疑问题是 502 错误。
您知道在这种情况下可能导致此错误的原因是什么吗?
我试过的
我尝试将script src=<path_to_socket_io>
客户端中的路径从/socket.io/socket.io.js
更改node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js
为此处所述,但没有帮助。
我还尝试在 Heroku 而不是 AppFog 上提供应用程序,但在这种情况下,即使我指定了 socket.io 版本 0.9.6 ,我仍然遇到这里描述的问题。
我还查看了以下问题,但到目前为止的评论似乎对我没有帮助。
socket.io create 502 Bad Gateway on connect / websocket invalid
Socket.IO node.js websocket连接无效端口8081
带有 node.js 的 socket.io 没有按预期工作
相关服务器代码
这是相关的服务器代码:
var server = http.createServer(function (req, res) {
...
});
var io = require('socket.io').listen(server);
// Define events that can be triggered by the client
io.sockets.on('connection', function (socket) {
socket.on('setServerVariable', function (value) {
...
});
...
});
server.listen(process.env.VCAPP_APP_PORT || 3000);
相关客户端代码
<script src="/socket.io/socket.io.js"></script>
<script>
window.onload = function () {
...
var socket = io.connect(window.location.hostname);
socket.emit('getServerVariable');
...
};
...
服务器日志
$ af logs sync
====> /logs/stdout.log <====
info: socket.io started
debug: served static content /socket.io.js
debug: client authorized
info: handshake authorized veNnUVtoDTIz-oudG7Pa
debug: setting request GET /socket.io/1/websocket/veNnUVtoDTIz-oudG7Pa
debug: set heartbeat interval for client veNnUVtoDTIz-oudG7Pa
warn: websocket connection invalid
info: transport end (undefined)
debug: set close timeout for client veNnUVtoDTIz-oudG7Pa
debug: cleared close timeout for client veNnUVtoDTIz-oudG7Pa
debug: cleared heartbeat interval for client veNnUVtoDTIz-oudG7Pa
debug: served static content /socket.io.js
debug: client authorized
info: handshake authorized 6AKyhROUNjqujk_uG7Pb
debug: setting request GET /socket.io/1/websocket/6AKyhROUNjqujk_uG7Pb
debug: set heartbeat interval for client 6AKyhROUNjqujk_uG7Pb
warn: websocket connection invalid
info: transport end (undefined)
debug: set close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: cleared close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: cleared heartbeat interval for client 6AKyhROUNjqujk_uG7Pb
debug: setting request GET /socket.io/1/xhr-polling/6AKyhROUNjqujk_uG7Pb?t=1348504130465
debug: setting poll timeout
debug: client authorized for
debug: clearing poll timeout
debug: xhr-polling writing 1::
debug: set close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: setting request GET /socket.io/1/xhr-polling/6AKyhROUNjqujk_uG7Pb?t=1348504130724
debug: setting poll timeout
debug: discarding transport
debug: cleared close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: xhr-polling received data packet 5:::{"name":"getServerVariable"}
debug: clearing poll timeout
debug: xhr-polling writing 5:::{"name":"printLog"}
debug: set close timeout for client 6AKyhROUNjqujk_uG7Pb
server.js: getServerVariable:
debug: setting request GET /socket.io/1/xhr-polling/6AKyhROUNjqujk_uG7Pb?t=1348504130980
debug: setting poll timeout
debug: clearing poll timeout
debug: xhr-polling writing ���23���5:::{"name":"printLog"}���39���5:::{"name":"setItemValue","args":[""]}���23���5:::{"name":"printLog"}
debug: set close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: discarding transport
debug: cleared close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: setting request GET /socket.io/1/xhr-polling/6AKyhROUNjqujk_uG7Pb?t=1348504131261
debug: setting poll timeout
debug: discarding transport
debug: cleared close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: clearing poll timeout
debug: xhr-polling writing 8::
debug: set close timeout for client 6AKyhROUNjqujk_uG7Pb
debug: xhr-polling closed due to exceeded duration
debug: setting request GET /socket.io/1/xhr-polling/6AKyhROUNjqujk_uG7Pb?t=1348504151659
debug: setting poll timeout
debug: discarding transport
debug: cleared close timeout for client 6AKyhROUNjqujk_uG7Pb