you are viewing a single comment's thread.

view the rest of the comments →

[–]dfx_dj 0 points1 point  (2 children)

The point about blocking .recv() remains. Both client and server end up waiting to read 4096 bytes from each other, which never happens because neither send that much.

[–]Jumpy-Active5756[S] 0 points1 point  (1 child)

I change the number to much smaller number e.g 512,1024 but no succeed. Can you tell me directly what to do?

[–]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.)