我不熟悉HTML5/javascript我用python创建了一个websocket服务器。
我想查看数据并在文本区域中添加接收到的消息,不确定出了什么问题,但在第一次尝试发送消息时,它可以正常工作,但在发送另一条消息时抛出“WebSocket is already in CLOSING or CLOSED state”。在
我是不是在html中遗漏了什么?在
{<1分$
var connection = new WebSocket("ws://localhost:8765");
connection.onopen = function () {
console.log('Connection Opened');
};
connection.onerror = function (error) {
console.log('WebSocket Error ' + error);
};
connection.onmessage = function (e) {
document.getElementById("rxConsole").value += e.data;
};
function sendMessage(msg){
console.log('I\'m sending data');
connection.send(document.getElementById("txBar").value);
document.getElementById("txBar").value = "";
}