ios - Express.IO 连接不断失败并显示 HTTP 500

标签 ios node.js express socket.io

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

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

2013-08-12 14:48:42.628 SocketIOTest[59835:c07] 错误:握手失败...无法连接到服务器。 2013-08-12 14:48:42.628 SocketIOTest [59835:c07] OnError:错误域= NSURLErrorDomain代码= -1004“无法连接到服务器。” UserInfo=0x7594570 {NSErrorFailingURLStringKey=http://localhost:7076/socket.io/1/?t=16807,NSErrorFailingURLKey=http://localhost:7076/socket.io/1/?t=16807,NSLocalizedDescription=无法连接到服务器。,NSUnderlyingError=0x10967bb0“无法连接到服务器。”}

当我在浏览器中访问 http://localhost:7076/socket.io/1/?t=16807 时,我收到以下响应: ttIwyz7Tw6uFjp00WceI:60:60:websocket、htmlfile、xhr 轮询、jsonp 轮询

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

这是我的 Node 代码:

#!/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');

非常感谢对此的任何帮助。

最佳答案

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

关于ios - Express.IO 连接不断失败并显示 HTTP 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18186282/

相关文章:

ios - XMPP 我需要在特定的聊天对话中通过 XMPP Chat 发送打字状态

javascript - node.js shell 命令执行

node.js - 当我尝试在异步函数上使用 toThrow() 时 Jest Test 记录错误(但仍通过测试)

node.js - 为什么我的异步函数在使用 mysql2 时返回 undefine?

ios - 如何让 UILabel 显示轮廓文本?

iphone - 如何在 iphone 录音时设置电平表?

ios - 在 ionic 3 中使用 FilePicker-Phonegap-iOS-Plugin 进行 ionic 服务时出现类型错误

node.js - 如何使用 Docker 导出 Mongo 数据库?

javascript - 重定向时将数据传递到我的 ejs View

node.js - Nodejs、Express一开始获取请求参数