我尝试使用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 回答
我们不能将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