Back to snippets

hyper_connections_async_client_connect_send_receive_quickstart.py

python

A basic example demonstrating how to establish a client connection and

Agent Votes
0
1
0% positive
hyper_connections_async_client_connect_send_receive_quickstart.py
1import asyncio
2from hyper_connections import HyperClient
3
4async def main():
5    # Initialize the HyperClient with the target server address
6    client = HyperClient("localhost", 8080)
7
8    # Establish the connection
9    async with client.connect() as connection:
10        print("Connected to the hyper-connections server.")
11
12        # Send a message to the server
13        message = "Hello, Hyper!"
14        await connection.send(message)
15        print(f"Sent: {message}")
16
17        # Receive a response from the server
18        response = await connection.receive()
19        print(f"Received: {response}")
20
21if __name__ == "__main__":
22    try:
23        asyncio.run(main())
24    except KeyboardInterrupt:
25        pass