Spaces:
Running
Running
File size: 858 Bytes
4a70d33 d2db5a7 7a10318 4a70d33 7a10318 4a70d33 10b984e 4a70d33 26bfbb3 4a70d33 7a10318 4a70d33 7a10318 4a70d33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import threading
import asyncio
import websockets
async def websocket_consumer(websocket, path):
try:
code = await websocket.recv()
async with websockets.connect('wss://ramesh-vani-wspython.hf.space') as wssocket:
await wssocket.send(code)
while True:
response = await wssocket.recv()
await websocket.send(response)
except websockets.exceptions.ConnectionClosedOK:
pass
class WebSocketThread(threading.Thread):
def run(self):
asyncio.set_event_loop(asyncio.new_event_loop())
start_server = websockets.serve(websocket_consumer, '0.0.0.0', 7860)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
websocket_thread = WebSocketThread()
websocket_thread.start() |