title: Why do I receive "WebSocket connection is closed: code = 1000 (OK), no reason"
body: <p>I have the following server:</p>
  
  <pre><code>import os
  import asyncio
  import websockets
  
  
  class Server:
  
      def get_port(self):
          return os.getenv('WS_PORT', '8765')
  
      def get_host(self):
          return os.getenv('WS_HOST', 'localhost')
  
      def start(self):
          return websockets.serve(self.handler, self.get_host(), self.get_port())
  
      async def handler(self, websocket, path):
          while True:
              async for message in websocket:
                  await websocket.send(message)
  </code></pre>
  
  <p>and the client:</p>
  
  <pre><code>import asyncio
  import websockets
  
  
  async def msg():
      async with websockets.connect('ws://localhost:8765') as websocket:
          await websocket.send('test message')
  
  asyncio.get_event_loop().run_until_complete(msg())
  </code></pre>
  
  <p>When I execute <code>asyncio.get_event_loop().run_until_complete(msg())</code> I receive the following error:</p>
  
  <pre><code>websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1000 (OK), no reason
  </code></pre>
  
  <p>Also <code>app.py</code> code:</p>
  
  <pre><code>#!/usr/bin/env python3.6
  
  import asyncio
  from server import Server
  
  
  if __name__ == '__main__':
      ws = Server()
      asyncio.get_event_loop().run_until_complete(ws.start())
      asyncio.get_event_loop().run_forever()
  </code></pre>
  
  <p>P.S. Added <code>while True</code> to <code>handler</code> as suggested in the comment below. But I still receive that error</p>