我正在尝试在Cloud Code中实现一个简单的SSE。

这是我打开连接的Express路线:

app.get('/call', function(req, res) {

  // let request last as long as possible
  req.socket.setTimeout(30000);

  //send headers for event-stream connection
  res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive'
  });

  res.write('\n');

  // The 'close' event is fired when a user closes their browser window.
  req.on("close", function() {

  });
});


我还确保包括:

var http = require('http');


问题是,我收到此错误:

  I2014-06-28T19:09:50.500Z] TypeError: Object function () {
    throw Error('IncomingMessage.socket not supported');
  } has no method 'setTimeout'
    at app.js:129:14
    at callbacks (express_router.js:161:37)
    at param (express_router.js:135:11)
    at pass (express_router.js:142:5)
    at Router._dispatch (express_router.js:170:5)
    at Object.router (express_router.js:33:10)
    at next (connect_proto.js:240:15)
    at Object.handle (app.js:88:7)
    at next (connect_proto.js:240:15)
    at Object.parseExpressCookieSession [as handle] (parse-express-cookie-session.js:315:7)


我也尝试过:

req.setTimeout(30000);


但是得到类似的错误。

我读到有关如何在更高版本的node之前不实现setTimeout的知识。这可能是问题吗?我找不到正在运行哪个版本的节点解析。

最佳答案

解析云代码不支持setTimeout()。他们似乎并没有在文档中的任何地方实际提及此问题,但是他们在旧论坛和此处的其他问题中已经无数次提及。

09-04 08:55