How to multiplex python coroutines( send and receive) in a websocket based chat client via an event loop <p>I am writing a console based chat server based on websockets and asyncio for learning both websockets and asyncio without using any other frameworks like Twisted, Tornado etc .. So far I have established the connection between client and server and am able to unicast and multicast messages between logged in users by writing send and receive in a single coroutine but this makes the clients block on either send or receive. So I tried by splitting up the send and receive coroutines but now after sending the first message to the server the client is unable to send any other message. </p> <p>Problems: </p> <ol> <li>I have two coroutines for receive and send respectively but I am not able to multiplex them to execute concurrently via the event loop. I managed to asynchronize the input from the stdin based on another article on stack overflow but I am still not able to run them concurrently so that send and receive can happen simultaneously.</li> <li>I am not sure if trying to make a connection with the websocket in both the coroutines is the correct way or not.</li> </ol> <p>Below is the code sample for the minimal client that i am using. What I have understood from asyncio till now is that when one of the coroutine is waiting over its "yield from", the other coroutine will get a chance to execute please point out if my understanding of the asyncio is correct or not:</p> <pre><code>import sys import asyncio import websockets qSend = asyncio.Queue() def got_stdin_data(qSend): asyncio.async(qSend.put(sys.stdin.readline())) def myClient_recv(): websocket = yield from websockets.connect('ws://localhost:8765/') while True: recvText = yield from websocket.recv() print("&gt;&gt;&gt; {}".format(recvText)) def myClient_send(): websocket = yield from websockets.connect('ws://localhost:8765/') while True: sendText = yield from qSend.get() yield from websocket.send(sendText) loop = asyncio.get_event_loop() loop.add_reader(sys.stdin, got_stdin_data, qSend) asyncio.async(myClient_recv()) asyncio.async(myClient_send()) loop.run_forever() </code></pre>