我正在使用 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/