【问题标题】:Express.IO connection keeps failing with HTTP 500Express.IO 连接不断失败并出现 HTTP 500
【发布时间】:2013-08-13 17:20:46
【问题描述】:

我正在使用 Express.IO 和 This iOS Client 尝试创建一个基本的套接字示例,但我似乎无法连接。

我尝试了所有可能在谷歌上找到的东西,但每次我的客户尝试连接时,我都会收到以下错误:

2013-08-12 14:48:42.628 SocketIOTest[59835:c07] ERROR: handshake failed ... Could not connect to the server. 2013-08-12 14:48:42.628 SocketIOTest[59835:c07] OnError: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x7594570 {NSErrorFailingURLStringKey=http://localhost:7076/socket.io/1/?t=16807, NSErrorFailingURLKey=http://localhost:7076/socket.io/1/?t=16807, NSLocalizedDescription=Could not connect to the server., NSUnderlyingError=0x10967bb0 "Could not connect to the server."}

当我在浏览器中转到 http://localhost:7076/socket.io/1/?t=16807 时,我得到以下响应: ttIwyz7Tw6uFjp00WceI:60:60:websocket,htmlfile,xhr-polling,jsonp-polling

但由于某种原因,在使用标头工具进行检查时,它实际上确实返回了 HTTP 500 错误。我真的不知道为什么。

这是我的节点代码:

#!/usr/bin/env node

var express     = require('express.io');
var app         = express().http().io();
var redisStore  = require('connect-redis')(express);

app.use(express.cookieParser());
app.use(express.session({
                            store:  new redisStore({
                                        host:   '192.168.33.10',
                                        port:   6386
                                    }),
                            secret: 'A>mVt*Cx87Kq^9:3}am$q67JYtGGAl'
                        })) ;

app.use(function(err, req, res, next){
    response.header('Access-Control-Allow-Origin', '*');
    response.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
    response.header('Access-Control-Allow-Credentials', 'true');
    response.header('Access-Control-Allow-Headers', 'Content-Type, Accept, Origin, Cookie');
    next();
});

app.set( 'origins', '*' );

app.io.on('connection', function (socket) {
    console.log("connection");
    socket.emit('news', { hello: 'world' });
});

app.listen(7076);
console.log('App API Server is listening on port 7076');

不胜感激。

【问题讨论】:

    标签: ios node.js express socket.io


    【解决方案1】:

    似乎您在 IOS 客户端中指的是 localhost:NSErrorFailingURLStringKey=http://localhost:7076/socket.io/1/?t=16807,而 node.js 服务器在某些外部 Linux 机器上运行。 请尝试连接到服务器。

    【讨论】:

    • 它是同一地址上的虚拟机,我的 iOS 客户端可以连接到常规的 Socket.IO ......我不确定 Express.IO 有什么问题 - 这就是我想要理解的.
    • 如果它在VM中运行,你确定localhost指的是正确的IP地址吗?你能告诉更多关于设置的信息吗? IOS 客户端是否在 IOS 设备上运行?
    • 是的,正如我所说的——在谈到 Socket.IO 服务时,我可以毫无问题地连接,但在 Express.IO 中尝试此代码时却没有。它实际上在我上面发布的 URL 中显示了正确的数据,但它返回 HTTP 500 而不是 200 OK。
    猜你喜欢
    • 1970-01-01
    • 2010-09-15
    • 2018-05-29
    • 2011-12-31
    • 2022-08-04
    • 2014-10-03
    • 2012-05-04
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多