Skip to content Skip to sidebar Skip to footer

I Got Problems With Making A Python Socket Server Receive Commands From A Python Socket Client

I got problems with making a Python socket server receive commands from a Python socket client. The server and client can send text to each other but I can't make text from the cli

Solution 1:

Everything here works fine but, maybe not the way you want it to. If you switch the order on a couple of the lines it will display your event string before you enter your server response.

import socket 

host = ''
port = 1010

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.bind((host, port)) 
s.listen(1) 
conn, addr = s.accept() 
print ("Connection from", addr) 
while True: 
    databytes = conn.recv(1024)
    if not databytes: break
    data = databytes.decode('utf-8')
    print("Recieved: "+(data))
    if data == "dodo":  # moved to before the `input` call
        print("hejhej")
    response = input("Reply: ")
    if response == "exit": 
        break
    conn.sendall(response.encode('utf-8')) 
conn.close()

Post a Comment for "I Got Problems With Making A Python Socket Server Receive Commands From A Python Socket Client"