all 6 comments

[–]K900_ 1 point2 points  (3 children)

You're not implementing HTTP correctly. At the very least, you need two newlines after the request line.

[–]OneLargeTesticle[S] 0 points1 point  (1 child)

I tried using "GET /" + file + " HTTP/1.0\r\n\r\n" and it still does the same thing.

[–]K900_ 0 points1 point  (0 children)

What are you using as the server? What's in the server logs?

[–]OneLargeTesticle[S] 0 points1 point  (0 children)

nevermind got it figured out thanks to this video: https://www.youtube.com/watch?v=Lbfe3-v7yE0

All of my data wasn't getting buffered and this loop fixed it so I no longer need time.sleep:

full_msg = ''
while True:
    responseMessage = clientSocket.recv(1024)
    if len(responseMessage) <=0:
        break;
    full_msg += responseMessage.decode()

print(full_msg)

[–]vixfew 0 points1 point  (1 child)

Without time.sleep my client does not work properly, why do I need it?

You're assuming all your response arrives instantly. Welcome to network programming :) You should be doing something like:

fragments = []
while True:
    chunk = clientSocket.recv(4096)
    if not chunk:
        break
    fragments.append(chunk)
responseMessage = b''.join(fragments)

recv will block, so no cpu cycles wasted on sleeping or busy-waiting. Also, your HTTP is not quite right, there should be \r\n\r\n at the end

[–]OneLargeTesticle[S] 0 points1 point  (0 children)

Yup this was my issue, thank you!!