我试图使用socket.io客户端连接到非socket.io websocket服务器。但我做不到。我正在尝试像这样连接到套接字服务器:
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 socket API连接到服务器时:
var socket = new WebSocket('wss://url-to-socket-api');
是工作。
是否有可能将Socket.io客户端与非Socket.io服务器一起使用?
我们不能将Socket.io客户端与非Socket.io服务器一起使用。在本例中,使用WebSocket。链接很少:
http://www.developerfusion.com/article/143158/an-Introduction-to-WebSockets/
http://code.tutsplus.com/tutorials/start-using-html5-websockets-today-net-13270