title: Python Send Data to Websockets
body: <p>I'm trying to stream my global mouse cursor position to a web client using a super simple websocket. </p>
  
  <p>I've got both of those things happening, and my client (in JS) works fine, but I don't know how to connect them; I want to send a websocket message whenever on <code>move()</code> is called, but everything I've tried throws an error. </p>
  
  <p>This code prints out mouse locations and runs the websocket, but how can I get the two to 'talk' to each other? </p>
  
  <pre><code>import asyncio
  import websockets
  from pynput import mouse
  
  def onmove(x, y):
      print(x,y)
  
  async def socket_handler(websocket, path):
      while True:
          message = await websocket.recv()
          print(f"Received {message}")
  
          resp = f'WS Message Was: {message}'
          await websocket.send(resp)
  
  
  listener = mouse.Listener(on_move = onmove)
  listener.start()
  
  start_server = websockets.serve(socket_handler, "127.0.0.1", 5000)
  asyncio.get_event_loop().run_until_complete(start_server)
  asyncio.get_event_loop().run_forever()
  </code></pre>
  
  <p>I feel like there must be a really obvious answer and I just don't understand async and event loops well enough</p>