title: Issues listening incoming messages in websocket client on Python 3.6
body: <p>I'm trying to build a <strong>websocket</strong> client on <strong>Python</strong> using websockets package from here: <a href="https://websockets.readthedocs.io/en/stable/api.html#module-websockets.client" rel="noreferrer">Websockets 4.0 API</a></p>
  
  <p>I'm using this way instead of example code because I want to create a websocket client class object, and use it as gateway.</p>
  
  <p>I'm having issues with my listener method (receiveMessage) on client side, which raises a ConnectionClose  exception at execution. I think maybe there is any problem with the loop.</p>
  
  <p>This is the simple webSocket client I've tried to build:</p>
  
  <pre><code>import websockets
  
  class WebSocketClient():
  
      def __init__(self):
          pass
  
      async def connect(self):
          '''
              Connecting to webSocket server
  
              websockets.client.connect returns a WebSocketClientProtocol, which is used to send and receive messages
          '''
          self.connection = await websockets.client.connect('ws://127.0.0.1:8765')
          if self.connection.open:
              print('Connection stablished. Client correcly connected')
              # Send greeting
              await self.sendMessage('Hey server, this is webSocket client')
              # Enable listener
              await self.receiveMessage()
  
  
      async def sendMessage(self, message):
          '''
              Sending message to webSocket server
          '''
          await self.connection.send(message)
  
      async def receiveMessage(self):
          '''
              Receiving all server messages and handling them
          '''
          while True:
              message = await self.connection.recv()
              print('Received message from server: ' + str(message))
  </code></pre>
  
  <p>And this is the main:</p>
  
  <pre><code>'''
      Main file
  '''
  
  import asyncio
  from webSocketClient import WebSocketClient
  
  if __name__ == '__main__':
      # Creating client object
      client = WebSocketClient()
      loop = asyncio.get_event_loop()
      loop.run_until_complete(client.connect())
      loop.run_forever()
      loop.close()
  </code></pre>
  
  <p>To test incoming messages listener, server sends two messages to client when it stablishes the connection.</p>
  
  <p>Client connects correctly to server, and sends the greeting. However, when client receives both messages, it raises a <strong>ConnectionClosed exception</strong> with code 1000 (no reason). </p>
  
  <p>If I remove the loop in the receiveMessage client method, client does not raise any exception, but it only receives one message, so I suppose I need a loop to keep listener alive, but I don't know exactly where or how.</p>
  
  <p>Any solution? </p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT:</strong> I realize that client closes connection (and breaks loop) when it receives all pending messages from server. However, I want client keeps alive listening future messages.</p>
  
  <p>In addition, I've tried to add another function whose task is to send a 'heartbeat' to server, but client closes connection anyway.</p>