<div dir="ltr"><div><div><div>Ian Kelly:<br><br>>> 2) In the blocked situaction even KeyboardInterrupt doesn't break the loop,<br>>> is that desired behavior? And why?<br>><br>> I don't think so. When I tried this locally (using Python 3.4.0, so<br>> replacing "async def" with "def" and "await" with "yield from" and<br>> "loop.create_task" with "asyncio.async") pressing Ctrl-C did interrupt<br>> the loop.<br>><br></div>Ok, I'll try to get more information and I'll eventually raise an issue.<br><br>>> 3) Are there some other issues with my code with respect to “best practices”<br>>> how to write a code like this?<br>><br>> There are a couple of approaches you could take. Since your protocol<br>> is so far text-based, I would suggest adding '\n' to the ends of your<br>> messages and using reader.readline instead of reader.read.<br>><br></div>For now, there is no protocol at all. I just wanted to first send all the data (of arbitrary size) and then wait for whole response. If there is really no way to close just one direction of a socket, maybe the easiest way is to have two socket pairs?<br><br><br>Marko Rauhamaa:<br><br>>>> 1) is there a way to close just one direction of the connection?<br>>><br>>> No. SOCK_STREAM sockets are always bidirectional.<br>> <br>> socket.shutdown(socket.SHUT_WR) does the trick.<br>> <br>> I think the asyncio.StreamWriter.write_eof() is the high-level<br>> equivalent.<br><br>You are right that writer.write_eof() behaves like writer.transport.get_extra_info("socket").shutdown(socket.SHUT_WR) – the server resumes and sends the response. However, the client still reads empty bytes afterwards.<br></div></div>