JavaScript connection from browser

Not a long time age I was writing a simple website (actually it is a survey which already has a domain name) There are a few functions website has to do: to send the choice to the server and recieve a simple answer. I wrote a simple python tcp

import socket
from threading import Thread

import struct, json
def send(conn, text):
    text = text.encode("utf-8")
    size = struct.pack("<I", len(text))
def recv(conn):
    size = struct.unpack("<I", conn.recv(4))[0]
    return conn.recv(size).decode("utf-8")

def func(conn):
    global answers
    while True:

sock = socket.socket()
sock.bind(("", 9090))


while True:
    conn, addr = sock.accept()
    th = Thread(target=func, args=(conn,))

How can I recieve my string ‘answer’ from browser and send back answer(I need only js example code)
Thank you in advance!

Source: JavaSript – Stack Overflow

November 1, 2021
Category : News
Tags: client | connection | javascript | python | sockets

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.