@@ -16,9 +16,9 @@ class Emu():
1616 class representation of a connection to Emu
1717 """
1818
19- def __init__ (self , hostname : str , port : int ):
20- self .hostname = hostname
21- self .port = port
19+ def __init__ (self ):
20+ self .hostname = "127.0.0.1"
21+ self .port = 14555
2222
2323 self ._send_queue = queue .Queue ()
2424 self ._recv_queue = queue .Queue ()
@@ -28,7 +28,7 @@ def __init__(self, hostname: str, port: int):
2828 self ._is_connected = False
2929
3030 def start_comms (self ):
31- self ._comms_thread = threading .Thread (target = self ._start_comms_loop )
31+ self ._comms_thread = threading .Thread (target = self ._start_comms_loop , daemon = True )
3232 self ._comms_thread .start ()
3333
3434 def send_image (self , path : str ):
@@ -53,22 +53,29 @@ def send_log(self, message: str, severity: str="normal"):
5353 }
5454 self ._send_queue .put (json .dumps (content ))
5555
56+ def send_msg (self , message : str ):
57+ """
58+ sends message as it is, follow the proper JSON API messages
59+ """
60+ self ._send_queue .put (message )
61+
5662 def set_on_connect (self , func : Callable ):
5763 self ._on_connect = func
5864
5965 def _start_comms_loop (self ):
6066 """
6167 starts connection loop with asyncio
6268 """
69+ print ("start_comms loop" )
6370 asyncio .run (self ._connect ())
64- pass
6571
6672 async def _connect (self ):
6773 """
6874 starts the server and waits for clients to connect. Once they do,
6975 self._handler handles each client
7076 """
71- async with serve (self ._handler , self .hostname , self .port ) as server :
77+ print ("connect" )
78+ async with serve (self ._handler , "" , self .port ) as server :
7279 await server .serve_forever ()
7380
7481
0 commit comments