'Use userinput in Server / client

right now i have the problem, that i have to implement a userinput in my server that use the command to send a msg. Right now i have the base from the code but i dont know how to implement the userinput.

import socket
from threading import Thread

host = socket.gethostname()
port = 12346
server_s = socket.socket()
server_s.bind((host, port))
stop_server = False

## Create Server

def starte_server():
    try:
        server_s.listen(5)
        while not stop_server:
            new_s, addr = server_s.accept()
            print("[SERVER] Verbindung erhalten von >", addr)
            new_s.send(b'Hallo Eric liebe gruesse vom Client')
            c_data = new_s.recv(1024)
            new_s.close()
    except Exception as ex:
             print("Exception at server", ex)

##Server (re-)starten
stop_server=True
try:
    client_s=socket.socket()
    client_s.connect((host, port))
    client_s.close()
except ConnectionRefusedError:
    pass
stop_server= False

server_thread = Thread(target=starte_server, args=())
server_thread.start()
print("===\nServer wurde gestartet\n===")

client_s = socket.socket()
client_s.connect((host, port))
grüße = client_s.recv(1024)
print("[CLIENT] Grüße an den Benutzer", grüße)
client_s.close()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source