Skip to content Skip to sidebar Skip to footer

My Python Socket Server Can Only Receive One Message From The Client

Hi i got a problem with my socket server or the client the problem is i can only send one message from the client to the server then the server stops receiving for some reason i wa

Solution 1:

There is nothing wrong with your code, but the LOGIC of it is wrong, in the Client.py file and particularly in this loop:

while True:
    response = input("Send: ") 
    if response == "exit": 
        s.sendall(response.encode('utf-8')) 

This will not send to your Server side anything but string exit because of this:

if response == "exit":

So you are asking your Client.py script to only send anything the user inputs matching the string exit otherwise it will not send.

It will send anything at the beginning before this while loop since you wrote:

initialMessage = input("Send: ") 
s.sendall(initialMessage.encode('utf-8'))

But after you are inside that while loop then you locked the s.sendall to only send exit string

You have to clean up your code logic.

Post a Comment for "My Python Socket Server Can Only Receive One Message From The Client"