I want to create a web socket using Python and JavaScript, but I get the following error.
(我想使用Python和JavaScript创建Web套接字,但是出现以下错误。)
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:
(Python代码:)
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>
ask by erfan jahanshahlo translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…