gpt4 book ai didi

sockets - 带有非 socket.io 服务器的 Socket.io 客户端

转载 作者:行者123 更新时间:2023-12-03 12:04:29 26 4
gpt4 key购买 nike

我尝试使用 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

关于sockets - 带有非 socket.io 服务器的 Socket.io 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34855156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com