title: Python websockets, unable to receive messages
body: <p>I'm using <a href="https://websockets.readthedocs.io/en/stable/" rel="nofollow noreferrer">websockets</a> in an python project i'm working on. The websocket is being run in an thread and given 2 <a href="https://docs.python.org/2/library/queue.html" rel="nofollow noreferrer">queue's</a> from the parent thread. I'm using javascript to connect to the websocket server.</p>
  
  <p>I'm able to get messages from the parent thread through<code>self.ssi.get(True)</code> and passed them through to the javascript websocket client.</p>
  
  <p>But i'm unable to receive messages from the client. When i use zaproxy i can see the messages going through. On the websocket server i'm also able to see the packets arrive on the interface. Python throws no error and <code>logger.setLevel(logging.DEBUG)</code> does not show messages arriving the same way as i'm able to see messages being send.</p>
  
  <p>I've been trying to solve this but i've run out of ideas to find the problem, any help is welcome.</p>
  
  <p>Python websocket server:</p>
  
  <pre><code>import websockets
  import logging
  import asyncio
  import ssl
  
  class websocket:
      def __init__(self,ssi,sso):
  
          self.ssi = ssi
          self.sso = sso
  
          logger = logging.getLogger('websockets')
          logger.setLevel(logging.DEBUG)
          # logger.addHandler(logging.FileHandler('debug.log'))
          logger.addHandler(logging.StreamHandler())
  
          sslc = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
          sslc.load_cert_chain(
              'keys/wss.server.crt',
              'keys/wss.server.key')
  
          loop = asyncio.new_event_loop()
          wsrv = websockets.serve(
              self.handler,
              host='0.0.0.0',
              port=9000,
              ssl=sslc,
              loop=loop)
  
          loop.run_until_complete(wsrv)
          loop.run_forever()
  
      async def handler(self, wss, path):
          consumer_task = asyncio.ensure_future(self.consumerHandler(wss, path))
          producer_task = asyncio.ensure_future(self.producerHandler(wss, path))
          done, pending = await asyncio.wait(
              [consumer_task, producer_task],
              return_when=asyncio.FIRST_COMPLETED,)
          for task in pending:
              task.cancel()
  
      async def producerHandler(self, wss, path):
          while True:
              msg = await self.producer()
              await wss.send(str(msg))
  
      async def consumerHandler(self, wss, path):
          async for msg in wss:
              await self.consumer(msg)
  
      async def producer(self):
          return self.ssi.get(True)
  
      async def consumer(self, msg):
          self.sso.put(msg.data)
  </code></pre>
  
  <p>Javascript client:</p>
  
  <pre><code>var ws;
  
  function ws_init() {
  
      ws = new WebSocket("wss://pri.local:9000/");
  
      ws.onopen = function(e) {
          output("connected");
      };
  
      ws.onmessage = function(e) {
          output("i: " + e.data);
      };
  
      ws.onclose = function() {
          output("disconnect");
      };
  
      ws.onerror = function(e) {
          output("onerror");
          console.log(e)
      };
  
  }
  
  function onSubmit() {
      var input = document.getElementById("input");
      ws.send(input.value);
      output("o: " + input.value);
      input.value = "";
      input.focus();
  }
  
  function onCloseClick() {
      ws.close();
  }
  
  function output(str) {
      var log = document.getElementById("log");
      var escaped = str.replace(/&amp;/, "&amp;amp;").replace(/&lt;/, "&amp;lt;").
          replace(/&gt;/, "&amp;gt;").replace(/"/, "&amp;quot;"); // "
          log.innerHTML = escaped + "&lt;br&gt;" + log.innerHTML;
  }
  </code></pre>