Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

javascript - 如何修复websocket错误:WebSocket握手期间出错:net :: ERR_CONNECTION_RESET(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创建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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...