send.py 753 B

12345678910111213141516171819202122232425
  1. import asyncio
  2. import websockets
  3. import sys
  4. async def hello(message):
  5. server="193.2.68.227"
  6. server="vangogh.fmf.uni-lj.si"
  7. uri = "ws://{}:8765".format(server)
  8. origin="merlin"
  9. async with websockets.connect(uri,origin=origin) as websocket:
  10. print('Sending {}'.format(message))
  11. await websocket.send(message)
  12. print(">>> {}".format(message))
  13. #receive nothing
  14. #greeting = await websocket.recv()
  15. #print(f"<<< {greeting}")
  16. if __name__ == "__main__":
  17. message=sys.argv[1]
  18. loop = asyncio.get_event_loop()
  19. # Blocking call which returns when the hello_world() coroutine is done
  20. loop.run_until_complete(hello(message))
  21. loop.close()