send.py 641 B

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