0

I've tried asking before and got a snarky response so I thought I'd try again, with a new problem that I've more recently run into. Basically, the same code is used for all 4 clients, and the same thing is being sent to each of them using a for loop. However, sometimes the output is different on certain clients and this changes every time I run the code. The client where the error(s) occur is also different. In the client script:

def receieve_message():
while True:
    
    command = client.recv(2048).decode(FORMAT)
        
    if command == "VOTE":
        round_one_vote = input("Who would you like to remove: ")
        message = ("VOTE1 "+round_one_vote)
        send(message)
        
    else:
        print(command)

I am sending in either the word VOTE from the server or a string of text. If it is a string of text it should print it out to the client. If it is VOTE it will take an input. I am sending the data from the server like this:

for client in clients:
        client.send("VOTE".encode(FORMAT))

When I've just run it, 3 out of 4 clients begin the input check, however the first client prints out VOTE, which should not be happening. When I run it a second, time the first two print out VOTE. There doesn't seem to be a pattern.

Additionally, there are random line breaks sometimes, also arbritarily

James Mann
  • 27
  • 3
  • This is too incomplete to diagnose, if you could provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that would go a long way in getting a useful answer. If you're not sending line breaks you won't receive any line breaks. One thing to notice is the assumption that whatever you transmit in a single `send()` will be received in single `recv()`. With stream sockets (`SOCK_STREAM`) that might happen sometimes and other times it won't. [This answer](https://stackoverflow.com/a/43420503/238704) has a detailed and important explanation. – President James K. Polk Jul 10 '22 at 17:28
  • @PresidentJamesK.Polk The code is quite large and tbh I wouldn't know how to reduce it, I feel like what I've provided should be fine for what I'm asking, since the problems only arise in those places (its the only place a server sends a message for the server script and the only time a client receives for the client script). The send() function is from a Tech With Tim video and it works fine, and even if it didn't i can fix that later, the problem is the if statement sometimes catching the command and sometimes not seemingly randomly, i was hoping there was some janky sockets answer – James Mann Jul 10 '22 at 23:35

0 Answers0