简体   繁体   中英

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. thank you

WebSocket connection to 'ws://localhost:1386/' failed: Error in connection establishment: 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

<!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

Try to change ' ws ://localhost:1386' to ' wss ://localhost:1386'

ws >>> wss

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM