File size: 1,206 Bytes
4a70d33
d2db5a7
 
7a10318
4a70d33
 
 
7a10318
 
8a4d308
4a70d33
10b984e
634fa35
4a70d33
634fa35
26bfbb3
634fa35
4a70d33
94a622b
4a70d33
 
 
 
7a10318
4a70d33
 
 
 
 
 
7a10318
84d9598
 
94a622b
84d9598
 
 
 
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
29
30
31
32
33
34
35
36
37
38
import threading
import asyncio
import websockets


async def websocket_consumer(websocket, path):
    
    try:
        code = await websocket.recv()
        print(code)
        async with websockets.connect('wss://ramesh-vani-wspython.hf.space') as wssocket:
            
            
            await wssocket.send(code)
            print('code sent')
            while True:
                print('loop')
                response = await wssocket.recv()
                print(response)
                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()
# 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()