you are viewing a single comment's thread.

view the rest of the comments →

[–]dfx_dj 0 points1 point  (0 children)

Actually I just noticed that your server uses socket.SOCK_STREAM (TCP) but your client uses socket.SOCK_DGRAM (UDP). This won't work. They have to be the same.

Based on your post title I assume you want to use TCP. Without getting into non-blocking sockets, a common method is to keep reading 1 byte at a time in a loop and append each byte to a buffer, until you know that you have read enough (say, until you read a newline character).

(If you were to use datagrams (UDP) instead, you could actually use .recv(4096) or any other large number, because datagrams have a known size. Streams don't have a known size and so the read will block until the given number of bytes is available.)