Files
itgmania212121/extern/IXWebSocket-11.3.2/test/compatibility/python/websockets/echo_server_interactive.py
T
Martin Natano dc49af3c59 Implement NetworkManager
For now there are two methods:

- `NETWORK:IsUrlAllowed()`: Check whether access to a certain URL is allowed.
- `NETWORK:HttpRequest()`: Perform an HTTP request.

By default access to the network is disabled for all target hosts. It
can be enabled by setting `HttpEnable=1` in the preferences. Individual
hosts have to be added to `HttpAllowHosts` as a comma separated list to
allow access.

See included docs for more details on usage.
2022-01-15 22:56:08 +01:00

29 lines
635 B
Python

#!/usr/bin/env python
# WS server example
import asyncio
import websockets
async def hello(websocket, path):
await websocket.send(f"> Welcome !")
name = await websocket.recv()
print(f"< {name}")
greeting = f"Hello {name}!"
await websocket.send(greeting)
print(f"> {greeting}")
async def echo(websocket, path):
msg = await websocket.recv()
print(f'Received {len(msg)} bytes')
await websocket.send(msg)
print('Serving on localhost:8766')
start_server = websockets.serve(echo, 'localhost', 8766)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()