Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

官方文档WebSocket 连不上服务器

$
0
0

@1112947 写道:

用官方文档里的WebSocket 连不上服务器是为什么?小白求解

var ws = new WebSocket("ws://echo.websocket.org");
ws.onopen = function (event) {
console.log("Send Text WS was opened.");
};
ws.onmessage = function (event) {
console.log("response text msg: " + event.data);
};
ws.onerror = function (event) {
console.log("Send Text fired an error");
};
ws.onclose = function (event) {
console.log("WebSocket instance closed.");
};

setTimeout(function () {
if (ws.readyState === WebSocket.OPEN) {
ws.send("Hello WebSocket, I'm a text message.");
}
else {
console.log("WebSocket instance wasn't ready...");
}
}, 3);

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>