Waiting for websocket.receive consumer in django-channels
<p>How to wait for a response from client after sending the client something using django-channels?</p>

<p>Whenever <code>Group.send()</code> is called from function <code>send_to_client()</code> and upon receiving the message by client, <code>send_to_client()</code> is expecting a response back from client which is getting received on <code>websocket.receive</code> channel.</p>

<p>Is there a way to return the <code>response_msg</code> in <code>send_to_client()</code> function?</p>

<p>Now I have reached <a href="http://channels.readthedocs.io/en/latest/faqs.html#why-isn-t-there-guaranteed-delivery-a-retry-mechanism" rel="nofollow noreferrer">here</a></p>

<p><code>Sample Code for consumers.py:</code></p>

<pre><code>def ws_receive(message):
    response_msg = message.content['text']
    return response_msg

def send_to_client(param1, param2, param3):
    Group.send({
      "text" : json.dumps({
        "First" : param1,
        "Second" : param2,
       })
    })
</code></pre>

<p>So once the message reaches at the client side, the client will send a response back to the server which will be received by the <code>ws_receive(message)</code> function through the <code>websocket.receive</code> channel which is defined in the <code>urls.py</code> file,</p>

<pre><code>channel_patterns = [
    route("websocket.receive", ws_receive),
    ...
] 
</code></pre>

<p>Is there a way to do this so that my function would look like this?</p>

<pre><code>def send_to_client(...):
    Group.send(...)
    response_msg = #response message from client
</code></pre>