swoole websocket 可以跟客户端建立长连接,
在 js 中连接 swoole websocket 时,
出现下面的错误提示:
Failed to construct ‘WebSocket’: The URL ‘192.168.1.250:9876’ is invalid
Uncaught DOMException: Failed to construct ‘WebSocket’: The URL’s scheme must be either ‘ws’ or ‘wss’. ‘http’ is not allowed.
意思是要使用 ws或wss协议,
不能使用 http
原因在 js 中没有写协议导致,
修改好即可
var wsUrl = 'ws://192.168.1.250:9876';