meta data for this page
socket
socket.makefile
When accessing socket as file:
- remember to call
file.flush()afterfile.write() - read() reads until EOF, so EOF for sockets means that connection is closed. Workarounds:
- use
\nat end of message andreadline()for reading - use own framing protocol. I.e. Encode 32bit size on first 4 bytes (using
struct). Then send data payload. On receiver side: read exactly 4 bytes and then N bytes specified in header.
- When file is in binary
bmode, usestr.encode()to convert strings into bytes