How to send answer back to client with QTcpServer?
Solved
Qt for Python
-
Hi all!
I am using QTcpServer to set up a tcp server.. so far so good, I can connect, send messages to the server and the server prints them just fine. Now I am trying to send an answer back to the server but it crashes. I am not able to figure out what I am doing wrong...
def on_readyRead(self): msg = self.socket.readAll() print(type(msg), msg.count()) print("Client Message:", msg) #<--------- this line is executed properly.... self.reply() def reply(self): cmd = "this is an answer.. :) " ucmd = unicode(cmd, "utf-8") self.socket.write(ucmd) self.socket.flush()
any help appreciated.. thank you!
-
@JonB it crashes with the windows messagebox that the application is not responding..
if i run it in debug mode I get this before it stops:
Client Message: b'123456,aaa'
Traceback (most recent call last):
File "C:/yolov5/CrateVision/main.py", line 185, in on_readyRead
self.reply()
File "C:/yolov5/CrateVision/main.py", line 197, in reply
ucmd = unicode(cmd, "utf-8")
TypeError: decoding str is not supportedProcess finished with exit code 1
-