-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppConnector.py
35 lines (27 loc) · 897 Bytes
/
AppConnector.py
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
import websockets
import asyncio
import websocket
import threading
class AppConnector:
CONNECTIONS =set()
SOCKET = "ws://0.0.0.0:7892/"
#HOST = "" # Empty denotes a localhost.
#PORT = 7892
def on_message(self,ws, message):
print('in on message')
print(message)
def on_open(self,ws):
print("Opened connection")
ws.send("Message from Client !")
def on_error(self,ws, error):
print(error)
def on_close(self,ws, close_status_code, close_msg):
print("### closed ###")
def wsthread(self):
print('in ws thread')
ws = websocket.WebSocketApp(self.SOCKET, on_message=self.on_message,on_close=self.on_close,on_open=self.on_open,on_error=self.on_error)
print('socket connected')
ws.run_forever()
if __name__ == '__main__':
appConnector = AppConnector()
appConnector.wsthread()