带有nonsocket.io服务器的Socket.io客户端

时间:2016-01-18 12:45:50

标签: sockets websocket socket.io

我尝试使用socket.io客户端连接到nonsocket.io websocket服务器。但我不能这样做。 我正在尝试连接到socket服务器,如下所示:

var socket = io.connect('wss://url-to-socket-api/');

得到错误:

XMLHttpRequest cannot load https://url-to-socket-api/socket.io/?EIO=3&transport=polling&t=1452852826678-0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.33.10' is therefore not allowed access. 

但是当我使用这样的Web套接字API连接到服务器时:

var socket = new WebSocket('wss://url-to-socket-api');

这是有效的。

是否可以将socket.io客户端与nonsocket.io服务器一起使用?

1 个答案:

答案 0 :(得分:1)

我们不能将Socket.io客户端与nonsocket.io服务器一起使用。在这种情况下使用WebSocket。链接很少:

http://www.developerfusion.com/article/143158/an-introduction-to-websockets/

http://code.tutsplus.com/tutorials/start-using-html5-websockets-today--net-13270