Requirements
Before connecting, make sure:
- The WebSocket server is enabled in the program
- The program is running
Connection URL
The server runs locally using the format:
ws://localhost:<port>
Python Example
Install the required library:
pip install websockets
Connection Example:
import asyncio
import websockets
import json
URI = "ws://localhost:8765"
async def main():
async with websockets.connect(URI) as ws:
print("Connected to WebSocket server")
await ws.send("Ping")
response = await ws.recv()
print("Ping ->", json.loads(response))
if __name__ == "__main__":
asyncio.run(main())