连接到node.js socket.io服务器:客户端无法连接 - 服务器报告“销毁nonsocket.io升级”

时间:2012-06-22 00:51:41

标签: node.js socket.io

我认为socket.io允许我实现一个websocket服务器。我有这个非常简单的代码:

// Require HTTP module (to start server) and Socket.IO
var http = require('http'), io = require('socket.io');

// start at port 8888
var server = http.createServer(function(req, res) {
    res.writeHead(200,{'Content-Type': 'text\html'});
    res.end('<h1>Welcome to the Notification Server</h1>'); 
});
server.listen(8888);

// Create Socket.io obj/pass to server
var socket = io.listen(server);

socket.on('connection', function(client) {
    console.log('Successful Websocket connection!');

    client.on('message', function(event) {
        console.log("Received message from client", event);     
    });

    client.on('disconnect', function() {
        console.log('Client has disconnected');
    });
});

我尝试了几个不同的测试客户端,所有这些客户端都在服务器上生成此消息: debug - 销毁nonsocket.io升级

一个这样的客户端尝试有一些这样的代码:

<html>
<script type="text/javascript">
<!---
window.WebSocket = window.WebSocket || window.MozWebSocket;

var ws = new WebSocket("ws://dev.ourserver.com:8888");

ws.onopen = function() {
    alert("Connected");
}

ws.onerror = function(error) {
    alert("Error:"+error);
}

// -->
</script>
<body>
</body>
</html>

只要我们加载页面,我就会在服务器上收到调试消息。

我认为这个库的重点是支持websocket协议,任何支持websockets的客户端都可以连接。

如果我按字面解释该消息,似乎表明server.io已检测到它正在连接到“non socket.io”客户端。这是否意味着如果不在客户端中使用socket.io,我就无法连接到此服务器?

0 个答案:

没有答案
相关问题