I'm using Express.IO and This iOS Client trying to create a basic socket example but I can't seem to be able to connect.
I tried everything I could possibly find on google but everytime my client tries connecting I get the following error:
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."}
When I go to http://localhost:7076/socket.io/1/?t=16807
in my browser I get this response: ttIwyz7Tw6uFjp00WceI:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
But for some reason when checking with header tools, it actually does return an HTTP 500 error. I'm really not sure why.
Here's my Node code:
#!/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');
Would appreciate any help on this.
it seems that you are referring to localhost: NSErrorFailingURLStringKey=http://localhost:7076/socket.io/1/?t=16807
in your IOS client, while the node.js server is running on some external Linux box. Try connecting to the server instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.