Exemplo n.º 1
0
 def listenThread(self):
   if self.listener is None:
     self.listener = socket()
   try:
     self.listener.bind((TARGET_IP, TARGET_PORT))
     self.listener.listen(0)
     print("Listening on {}:{}".format(TARGET_IP, TARGET_PORT))
     while 1:
       newSocket, addr = self.listener.accept()
       newClient = ClientWorker(newSocket, self.queue, addr)
       newClient.start()
       self.clientList.append(newClient)
       print("Client connected from {}".format(addr))
   finally:
     self.close()
Exemplo n.º 2
0
usbQ = Queue()

# Instantiating a rover object
#simulation = rover()

# Instantiation of a whole message
#message = []

# Print out what port is in use
print('Port: ' + usb.name)
# Building a new client worker object
usbClient = ClientWorker(usb, usbQ, usb.name, usb.write, usb.readline)

print('Client built')
# Start the client worker object thread
usbClient.start()

print('Client thread started')
# Look to receive a message <- Blocking
outmsg = InternalMessage(CLIENT, DEBUG_MSG, b'hello')
def outfunc():
    try:
        while True:
            usbClient.send(outmsg)
    except serial.SerialException:
        pass
outthread = Thread(target=outfunc, daemon=True)
#outthread.start()
while True:
    msg = usbQ.get()
    if msg.msgtype == INITIALIZE: