Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to send answer back to client with QTcpServer?
QtWS25 Last Chance

How to send answer back to client with QTcpServer?

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 366 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Igor86
    wrote on last edited by
    #1

    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!

    JonBJ 1 Reply Last reply
    0
    • I Igor86

      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!

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Igor86
      What exactly do you mean by "crashes", what output do you see, and where from your code does it "crash"?

      I 1 Reply Last reply
      0
      • JonBJ JonB

        @Igor86
        What exactly do you mean by "crashes", what output do you see, and where from your code does it "crash"?

        I Offline
        I Offline
        Igor86
        wrote on last edited by
        #3

        @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 supported

        Process finished with exit code 1

        JonBJ 1 Reply Last reply
        0
        • I Igor86

          @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 supported

          Process finished with exit code 1

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Igor86 said in How to send answer back to client with QTcpServer?:

          ucmd = unicode(cmd, "utf-8")
          TypeError: decoding str is not supported

          So the error message already tells you what the issue is. This is a Python issue, nothing to do with Qt.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved