2014-02-26 98 views
0

我有一個運行WebSocket的Node.js服務器。 (使用柚子)。我能夠運行一個Web應用程序並連接到它(localhost @port 3104)。IOS上的我的Socket.io無法與websocket服務器握手

然而,當我嘗試使用socket.io(SocketRocket)爲IOS和連接到同一本地主機和端口,我得到這個錯誤:

Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x6c723c0 
{NSErrorFailingURLStringKey=http://127.0.0.1:3014/socket.io/1/?t=16807, NSErrorFailingURLKey=http://127.0.0.1:3014/socket.io/1/?t=16807, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x6c72400 "The request timed out."} 
:錯誤的

> http://127.0.0.1:3014/socket.io/1/?t=16807 
> "ERROR: handshake failed ... The request timed out" 

詳細

我試過了。 127.0.01,本地主機...甚至明確的IP地址..所有失敗

任何想法我應該檢查什麼? 它應該是「http」協議嗎?或者wss?

+0

可能的重複[如何使用SocketRocket與socket.io?](http://stackoverflow.com/questions/9302561/how-to-use-socketrocket-with-socket-io) –

回答

0

得到它的工作..我只是不能運行一個websocket服務器。我必須運行一個socket.io服務器...然後它可以工作。

+0

你好,你可以請求幫助我在js文件中。我得到錯誤:握手失敗...請求超時「每次,而在瀏覽器中它會生成文件。 –

+0

var express = require('express'); var app = express(); var server = app .listen(3000); var io = require('socket.io')。listen(server); server.listen(3000,function(){console.log('listen on *:3000');}) ; var users = {}; app.get('/',function(req,res){res.sendfile('index.html');}); io.sockets.on('connection',function (socket){「register」,function(username){ \t \t users [username] = socket.id; \t}}; socket.on('chat message',function(msg){io.sockets.emit('new message',msg); }); });