lundi 24 février 2020

java script websocket can't connect to python serveur

i want that the serveur connect and send data to the python serveur but unfortunately i have this errorSCRIPT12029: SCRIPT12029: WebSocket Error: Network Error 12029, i have seen on this website Connecting to TCP Socket from browser using javascript at the second post when he says You can use also attempt to use HTML5 Web Sockets (Although this is not direct TCP communication): so this is the java script html code

<!DOCTYPE html>
<html>
<head>
    <title>JS #0</title>
</head>
<body>
    <script>
        try{
            var connection = new WebSocket('ws://127.0.0.1:1555');

            connection.onopen = function () {
                connection.send('Ping'); // Send the message 'Ping' to the server
            };
        }catch(Exception){
        }
                </script>
</body>
</html>

python

# coding: utf-8

import socket

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
a=1
if(a==1):
    try:

        socket.bind(('', 1555))


        socket.listen(5)
        print("client start")
        client, address = socket.accept()
        print ("{} connected".format( address ))

        response = client.recv(255)
        if response != "":
                print(response)
    except Exception as e:
        print(e)
    finally:
        socket.close()



Aucun commentaire:

Enregistrer un commentaire