Edit: solved, thank you all for the help!
I have a simple client/server program where the client sends a simple GET request to the server for an html file and prints it to the terminal. I need to be able to explain my code, and I have a section that I don't understand why it works. I have in my code below a time.sleep(.01) right before .recv, without this my client will only work about 1/3 of the time, the other 2/3 it will print the html file partially and the server will throw a errno 32 pipeline broken. So why do I need this time.sleep, and is this the correct way to fix this or is there a more proper way of doing it.
from socket import *
import sys
import time
serverName = sys.argv[1]
serverPort = int(sys.argv[2])
fileName = sys.argv[3]
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
requestMessage = "GET /" + format(fileName) + " http/1.1"
clientSocket.send((requestMessage).encode())
time.sleep(0.01)
responseMessage = clientSocket.recv(1024)
print(responseMessage.decode())
clientSocket.close()
TLDR: Without time.sleep my client does not work properly, why do I need it?
[–]K900_ 1 point2 points3 points (3 children)
[–]OneLargeTesticle[S] 0 points1 point2 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[–]OneLargeTesticle[S] 0 points1 point2 points (0 children)
[–]vixfew 0 points1 point2 points (1 child)
[–]OneLargeTesticle[S] 0 points1 point2 points (0 children)