import asyncio
import websockets
import json

# Define your custom payload
custom_payload = {
    "type": "message",
    "data": "This is a benign payload from the Python server"
}

async def handler(websocket, path):
    print("Client connected")
    await websocket.send(json.dumps(custom_payload))
    try:
        async for message in websocket:
            print("Received from client:", message)
    except websockets.exceptions.ConnectionClosed:
        print("Client disconnected")

async def main():
    async with websockets.serve(handler, "localhost", 8765):
        print("WebSocket server listening on ws://localhost:8765")
        await asyncio.Future()  # run forever

if __name__ == "__main__":
    asyncio.run(main())
