WebSocket已经处于CLOSING或CLOSED状态-HTML

时间:2019-03-02 13:06:24

标签: python html html5 websocket

我是HTML5 / javascript的新手,我已经使用python创建了一个Websocket服务器。
我想查看数据并在文本区域中添加接收到的消息,不知道出了什么问题,但是在第一次尝试发送消息时可以正常工作,但是在发送另一个消息时会抛出“ static void cursor_position_callback(GLFWwindow *window, double x, double y) { // (x, y) are relative! ... glfwSetCursorPos(window, 0, 0); } int main(...) { GLFWwindow *window = ...; ... glfwSetCursorPosCallback(window, cursor_position_callback); ... glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); ... } ”。 / p>

我是否缺少html中的某些内容?

WebSocket is already in CLOSING or CLOSED state

Python代码:

<!DOCTYPE HTML>

<html>
   <head>
      <script type="text/javascript">
		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 = "";
		}
</script>

	  
		
   </head>
   <body">
   <div>
		 <textarea id="rxConsole"></textarea
	</div>
	<hr/>
	<div>
		<input type ="text" id="txBar" onkeydown="if(event.keyCode == 13) sendMessage();" />
   </body>
</html>

来自Chrome:

enter image description here

0 个答案:

没有答案