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 answers= def send(conn, text): text = text.encode("utf-8") size = struct.pack("<I", len(text)) conn.send(size) conn.send(text) def recv(conn): size = struct.unpack("<I", conn.recv(4)) return conn.recv(size).decode("utf-8") def func(conn): global answers while True: mess=recv(conn) answers.append(mess) send(conn,'answer') sock = socket.socket() sock.bind(("", 9090)) sock.listen(10) while True: conn, addr = sock.accept() th = Thread(target=func, args=(conn,)) th.start()
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 OverflowNovember 1, 2021