====== socket ====== [[https://docs.python.org/3/library/socket.html|socket — Low-level networking interface]] ===== socket.makefile ===== [[https://docs.python.org/3/library/socket.html#socket.socket.makefile|socket.makefile]] When accessing socket as file: * remember to call ''file.flush()'' after ''file.write()'' * read() reads until EOF, so EOF for sockets means that connection is closed. Workarounds: * use ''\n'' at end of message and ''readline()'' 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 ''b'' mode, use ''str.encode()'' to convert strings into bytes