Made them communicate but somehow broke "hello" messages
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import sys
|
||||
import asyncio
|
||||
|
||||
from macros import *
|
||||
import bot as botPy
|
||||
import data
|
||||
import py_websocket
|
||||
|
||||
|
||||
def main():
|
||||
@@ -17,5 +19,11 @@ def main():
|
||||
py_print("Reading data...")
|
||||
data.read_data(bot)
|
||||
|
||||
if "--py" not in bot.args:
|
||||
py_print("Connecting to local websocket...")
|
||||
asyncio.run(py_websocket.websocket_client())
|
||||
|
||||
py_websocket.send_message("[Connection test] Hello from Python!")
|
||||
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,20 @@
|
||||
import websockets
|
||||
from macros import py_print
|
||||
|
||||
ws_global = None
|
||||
|
||||
async def send_message(message: str):
|
||||
global ws_global
|
||||
if ws_global:
|
||||
await ws_global.send(message)
|
||||
|
||||
|
||||
async def websocket_client():
|
||||
global ws_global
|
||||
async with websockets.connect("ws://127.0.0.1:9001") as ws:
|
||||
ws_global = ws
|
||||
py_print("Connected webSocket server on ws://127.0.0.1:9001")
|
||||
|
||||
while True:
|
||||
response = await ws.recv()
|
||||
py_print(f"Received from Rust: {response}")
|
||||
Reference in New Issue
Block a user