-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
23 lines (19 loc) · 892 Bytes
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import argparse
import asyncio
import websockets
# Function to send a message and receive a response from the WebSocket server
async def send_message(url, message):
async with websockets.connect(url) as websocket:
await websocket.send(message)
response = await websocket.recv()
return response
def main(args):
# Send a message to the WebSocket server and receive a response
response = asyncio.get_event_loop().run_until_complete(send_message(args.url, args.message))
print("Response from server:", response)
argparser = argparse.ArgumentParser()
argparser.add_argument("--url", type=str, default="ws://localhost:8765", help="URL to connect to the WebSocket server")
argparser.add_argument("--message", type=str, default="Hello, world!", help="Message to send to the server")
args = argparser.parse_args()
if __name__ == "__main__":
main(args)