Code: Select all
from messages import SayText2
import enum
import threading
import websocket
from listeners.tick import GameThread
def on_ws_open(ws):
print('socket connected')
ws.send("Hello")
def on_ws_close(ws, close_status_code, close_msg):
print(f'Socket closed: {close_msg}\n Status code: {close_status_code}')
def on_ws_message(ws, message):
print(message)
def on_ws_error(ws, error):
print('Socket error')
# ws.send("Hello, server")
def start_ws():
ws = websocket.WebSocketApp(
url="ws://192.168.0.11:1337/ws",
on_close=on_ws_close,
on_message=on_ws_message,
on_error=on_ws_error,
on_open=on_ws_open
)
print("WebsocketApp created")
ws_run = ws.run_forever(
ping_interval=5
)
print("after ws_run")
def load():
thread = GameThread(target=start_ws)
thread.daemon = True
thread.start()
def unload():
pass

Sorry if something is messed up, i have little experience with python and threading