[英]How to fix websocket error: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
I want to create a web socket using Python and JavaScript, but I get the following error.我想使用 Python 和 JavaScript 创建一个网络套接字,但出现以下错误。 thank you
谢谢你
WebSocket connection to 'ws://localhost:1386/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
WebSocket 连接到“ws://localhost:1386/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED
Python Code:蟒蛇代码:
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.bind(("localhost", 1386))
s.listen(5)
client, addr = s.accept()
print("connected to "+ str(addr))
client.sendall("hi. im server".encode())
client.close()
JavaScript - HTML Code JavaScript - HTML 代码
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<script>
var socket = new WebSocket('ws://localhost:1386');
</script>
</head>
<body>
</body>
</html>
Error during WebSocket handshake: net::ERR_CONNECTION_RESET WebSocket 握手期间出错:net::ERR_CONNECTION_RESET
Try to change ' ws ://localhost:1386' to ' wss ://localhost:1386'尝试将 ' ws ://localhost:1386' 更改为 ' wss ://localhost:1386'
ws >>> wss ws >>> wss
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.