send.py 815 B

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