Python QtNetwork.QTcpSocket.readAll() and QtNetwork.QTcpSocket.write() not working












0















I'm doing a simple socket connection and the read.All() and write() are not giving me anything back.



import PySide.QtNetwork as Network
import PySide.QtCore as Core

proxyAddress = '127.0.0.1'
proxyPort = 1025
tcpSocket = Network.QTcpSocket()
tcpSocket.connectToHost(proxyAddress, proxyPort)


tcpSocket.state() gives



"PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


When I then try to send something, I get this back:



tcpSocket.write("Hello")
5L


And for readAll():



tcpSocket.readAll()
PySide.QtCore.QByteArray('')


Oh and to disconnect I try:



tcpSocket.disconnectFromHost()


and it comes back with the next line to write as if it was successful in disconnecting but when I check the state:



tcpSocket.state()
"PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


Any help is appreciated.










share|improve this question





























    0















    I'm doing a simple socket connection and the read.All() and write() are not giving me anything back.



    import PySide.QtNetwork as Network
    import PySide.QtCore as Core

    proxyAddress = '127.0.0.1'
    proxyPort = 1025
    tcpSocket = Network.QTcpSocket()
    tcpSocket.connectToHost(proxyAddress, proxyPort)


    tcpSocket.state() gives



    "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


    When I then try to send something, I get this back:



    tcpSocket.write("Hello")
    5L


    And for readAll():



    tcpSocket.readAll()
    PySide.QtCore.QByteArray('')


    Oh and to disconnect I try:



    tcpSocket.disconnectFromHost()


    and it comes back with the next line to write as if it was successful in disconnecting but when I check the state:



    tcpSocket.state()
    "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


    Any help is appreciated.










    share|improve this question



























      0












      0








      0








      I'm doing a simple socket connection and the read.All() and write() are not giving me anything back.



      import PySide.QtNetwork as Network
      import PySide.QtCore as Core

      proxyAddress = '127.0.0.1'
      proxyPort = 1025
      tcpSocket = Network.QTcpSocket()
      tcpSocket.connectToHost(proxyAddress, proxyPort)


      tcpSocket.state() gives



      "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


      When I then try to send something, I get this back:



      tcpSocket.write("Hello")
      5L


      And for readAll():



      tcpSocket.readAll()
      PySide.QtCore.QByteArray('')


      Oh and to disconnect I try:



      tcpSocket.disconnectFromHost()


      and it comes back with the next line to write as if it was successful in disconnecting but when I check the state:



      tcpSocket.state()
      "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


      Any help is appreciated.










      share|improve this question
















      I'm doing a simple socket connection and the read.All() and write() are not giving me anything back.



      import PySide.QtNetwork as Network
      import PySide.QtCore as Core

      proxyAddress = '127.0.0.1'
      proxyPort = 1025
      tcpSocket = Network.QTcpSocket()
      tcpSocket.connectToHost(proxyAddress, proxyPort)


      tcpSocket.state() gives



      "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


      When I then try to send something, I get this back:



      tcpSocket.write("Hello")
      5L


      And for readAll():



      tcpSocket.readAll()
      PySide.QtCore.QByteArray('')


      Oh and to disconnect I try:



      tcpSocket.disconnectFromHost()


      and it comes back with the next line to write as if it was successful in disconnecting but when I check the state:



      tcpSocket.state()
      "PySide.QtNetwork.QAbstractSocket.SocketState.ConnectingState"


      Any help is appreciated.







      python pyside qtcpsocket






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 19:07









      eyllanesc

      79.8k103258




      79.8k103258










      asked Nov 20 '18 at 11:45









      mikanimmikanim

      165




      165
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First of all the state that signals is ConnectingState that indicates that the connection has not been made so it is not correct to perform any task at that moment, you must wait for the status to be ConnectedState. On the other hand, the port you point out is probably being used by another application since it is a small number that are usually reserved for another task. In the next part I show an example of a server and a client (first launch the server and then you can launch the number of clients you want.). Finally in Qt the tasks should not be performed synchronously but through signals since the Qt event-loop needs to update internal and external variables states.



          server.py



          import uuid
          from PySide import QtCore, QtNetwork

          class ServerManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ServerManager, self).__init__(parent)
          self._server = QtNetwork.QTcpServer(self)
          self._server.newConnection.connect(self.on_newConnection)
          self._clients = {}

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._server.listen(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot()
          def on_newConnection(self):
          socket = self._server.nextPendingConnection()
          socket.readyRead.connect(self.on_readyRead)
          if socket not in self._clients:
          self._clients[socket] = uuid.uuid4()

          @QtCore.Slot()
          def on_readyRead(self):
          socket = self.sender()
          resp = socket.readAll()
          code = self._clients[socket]
          print("From[{}]- message: {}".format(code, resp))
          socket.write("Server: " + str(resp)[::-1])

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)

          address = '127.0.0.1'
          port = 9000
          server = ServerManager()
          if not server.launch(address, port):
          sys.exit(-1)
          sys.exit(app.exec_())


          client.py



          from PySide import QtCore, QtNetwork

          class ClientManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ClientManager, self).__init__(parent)
          self._socket = QtNetwork.QTcpSocket(self)
          self._socket.stateChanged.connect(self.on_stateChanged)
          self._socket.readyRead.connect(self.on_readyRead)
          self._timer = QtCore.QTimer(self, interval=1000)
          self._timer.timeout.connect(self.sendMessage)

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._socket.connectToHost(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot(QtNetwork.QAbstractSocket.SocketState)
          def on_stateChanged(self, state):
          if state == QtNetwork.QAbstractSocket.ConnectedState:
          self._timer.start()
          print("connected")
          elif state == QtNetwork.QAbstractSocket.UnconnectedState:
          print("disconnected")
          QtCore.QCoreApplication.quit()

          @QtCore.Slot()
          def sendMessage(self):
          if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
          msg = QtCore.QDateTime.currentDateTime().toString()
          self._socket.write(msg)

          @QtCore.Slot()
          def on_readyRead(self):
          print("Response: ", self._socket.readAll())

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)
          address = '127.0.0.1'
          port = 9000
          server = ClientManager()
          server.launch(address, port)
          sys.exit(app.exec_())





          share|improve this answer
























          • Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

            – mikanim
            Nov 20 '18 at 22:01











          • @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

            – eyllanesc
            Nov 20 '18 at 22:02











          • @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

            – eyllanesc
            Nov 20 '18 at 22:41











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392316%2fpython-qtnetwork-qtcpsocket-readall-and-qtnetwork-qtcpsocket-write-not-worki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          First of all the state that signals is ConnectingState that indicates that the connection has not been made so it is not correct to perform any task at that moment, you must wait for the status to be ConnectedState. On the other hand, the port you point out is probably being used by another application since it is a small number that are usually reserved for another task. In the next part I show an example of a server and a client (first launch the server and then you can launch the number of clients you want.). Finally in Qt the tasks should not be performed synchronously but through signals since the Qt event-loop needs to update internal and external variables states.



          server.py



          import uuid
          from PySide import QtCore, QtNetwork

          class ServerManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ServerManager, self).__init__(parent)
          self._server = QtNetwork.QTcpServer(self)
          self._server.newConnection.connect(self.on_newConnection)
          self._clients = {}

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._server.listen(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot()
          def on_newConnection(self):
          socket = self._server.nextPendingConnection()
          socket.readyRead.connect(self.on_readyRead)
          if socket not in self._clients:
          self._clients[socket] = uuid.uuid4()

          @QtCore.Slot()
          def on_readyRead(self):
          socket = self.sender()
          resp = socket.readAll()
          code = self._clients[socket]
          print("From[{}]- message: {}".format(code, resp))
          socket.write("Server: " + str(resp)[::-1])

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)

          address = '127.0.0.1'
          port = 9000
          server = ServerManager()
          if not server.launch(address, port):
          sys.exit(-1)
          sys.exit(app.exec_())


          client.py



          from PySide import QtCore, QtNetwork

          class ClientManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ClientManager, self).__init__(parent)
          self._socket = QtNetwork.QTcpSocket(self)
          self._socket.stateChanged.connect(self.on_stateChanged)
          self._socket.readyRead.connect(self.on_readyRead)
          self._timer = QtCore.QTimer(self, interval=1000)
          self._timer.timeout.connect(self.sendMessage)

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._socket.connectToHost(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot(QtNetwork.QAbstractSocket.SocketState)
          def on_stateChanged(self, state):
          if state == QtNetwork.QAbstractSocket.ConnectedState:
          self._timer.start()
          print("connected")
          elif state == QtNetwork.QAbstractSocket.UnconnectedState:
          print("disconnected")
          QtCore.QCoreApplication.quit()

          @QtCore.Slot()
          def sendMessage(self):
          if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
          msg = QtCore.QDateTime.currentDateTime().toString()
          self._socket.write(msg)

          @QtCore.Slot()
          def on_readyRead(self):
          print("Response: ", self._socket.readAll())

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)
          address = '127.0.0.1'
          port = 9000
          server = ClientManager()
          server.launch(address, port)
          sys.exit(app.exec_())





          share|improve this answer
























          • Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

            – mikanim
            Nov 20 '18 at 22:01











          • @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

            – eyllanesc
            Nov 20 '18 at 22:02











          • @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

            – eyllanesc
            Nov 20 '18 at 22:41
















          1














          First of all the state that signals is ConnectingState that indicates that the connection has not been made so it is not correct to perform any task at that moment, you must wait for the status to be ConnectedState. On the other hand, the port you point out is probably being used by another application since it is a small number that are usually reserved for another task. In the next part I show an example of a server and a client (first launch the server and then you can launch the number of clients you want.). Finally in Qt the tasks should not be performed synchronously but through signals since the Qt event-loop needs to update internal and external variables states.



          server.py



          import uuid
          from PySide import QtCore, QtNetwork

          class ServerManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ServerManager, self).__init__(parent)
          self._server = QtNetwork.QTcpServer(self)
          self._server.newConnection.connect(self.on_newConnection)
          self._clients = {}

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._server.listen(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot()
          def on_newConnection(self):
          socket = self._server.nextPendingConnection()
          socket.readyRead.connect(self.on_readyRead)
          if socket not in self._clients:
          self._clients[socket] = uuid.uuid4()

          @QtCore.Slot()
          def on_readyRead(self):
          socket = self.sender()
          resp = socket.readAll()
          code = self._clients[socket]
          print("From[{}]- message: {}".format(code, resp))
          socket.write("Server: " + str(resp)[::-1])

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)

          address = '127.0.0.1'
          port = 9000
          server = ServerManager()
          if not server.launch(address, port):
          sys.exit(-1)
          sys.exit(app.exec_())


          client.py



          from PySide import QtCore, QtNetwork

          class ClientManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ClientManager, self).__init__(parent)
          self._socket = QtNetwork.QTcpSocket(self)
          self._socket.stateChanged.connect(self.on_stateChanged)
          self._socket.readyRead.connect(self.on_readyRead)
          self._timer = QtCore.QTimer(self, interval=1000)
          self._timer.timeout.connect(self.sendMessage)

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._socket.connectToHost(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot(QtNetwork.QAbstractSocket.SocketState)
          def on_stateChanged(self, state):
          if state == QtNetwork.QAbstractSocket.ConnectedState:
          self._timer.start()
          print("connected")
          elif state == QtNetwork.QAbstractSocket.UnconnectedState:
          print("disconnected")
          QtCore.QCoreApplication.quit()

          @QtCore.Slot()
          def sendMessage(self):
          if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
          msg = QtCore.QDateTime.currentDateTime().toString()
          self._socket.write(msg)

          @QtCore.Slot()
          def on_readyRead(self):
          print("Response: ", self._socket.readAll())

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)
          address = '127.0.0.1'
          port = 9000
          server = ClientManager()
          server.launch(address, port)
          sys.exit(app.exec_())





          share|improve this answer
























          • Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

            – mikanim
            Nov 20 '18 at 22:01











          • @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

            – eyllanesc
            Nov 20 '18 at 22:02











          • @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

            – eyllanesc
            Nov 20 '18 at 22:41














          1












          1








          1







          First of all the state that signals is ConnectingState that indicates that the connection has not been made so it is not correct to perform any task at that moment, you must wait for the status to be ConnectedState. On the other hand, the port you point out is probably being used by another application since it is a small number that are usually reserved for another task. In the next part I show an example of a server and a client (first launch the server and then you can launch the number of clients you want.). Finally in Qt the tasks should not be performed synchronously but through signals since the Qt event-loop needs to update internal and external variables states.



          server.py



          import uuid
          from PySide import QtCore, QtNetwork

          class ServerManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ServerManager, self).__init__(parent)
          self._server = QtNetwork.QTcpServer(self)
          self._server.newConnection.connect(self.on_newConnection)
          self._clients = {}

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._server.listen(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot()
          def on_newConnection(self):
          socket = self._server.nextPendingConnection()
          socket.readyRead.connect(self.on_readyRead)
          if socket not in self._clients:
          self._clients[socket] = uuid.uuid4()

          @QtCore.Slot()
          def on_readyRead(self):
          socket = self.sender()
          resp = socket.readAll()
          code = self._clients[socket]
          print("From[{}]- message: {}".format(code, resp))
          socket.write("Server: " + str(resp)[::-1])

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)

          address = '127.0.0.1'
          port = 9000
          server = ServerManager()
          if not server.launch(address, port):
          sys.exit(-1)
          sys.exit(app.exec_())


          client.py



          from PySide import QtCore, QtNetwork

          class ClientManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ClientManager, self).__init__(parent)
          self._socket = QtNetwork.QTcpSocket(self)
          self._socket.stateChanged.connect(self.on_stateChanged)
          self._socket.readyRead.connect(self.on_readyRead)
          self._timer = QtCore.QTimer(self, interval=1000)
          self._timer.timeout.connect(self.sendMessage)

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._socket.connectToHost(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot(QtNetwork.QAbstractSocket.SocketState)
          def on_stateChanged(self, state):
          if state == QtNetwork.QAbstractSocket.ConnectedState:
          self._timer.start()
          print("connected")
          elif state == QtNetwork.QAbstractSocket.UnconnectedState:
          print("disconnected")
          QtCore.QCoreApplication.quit()

          @QtCore.Slot()
          def sendMessage(self):
          if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
          msg = QtCore.QDateTime.currentDateTime().toString()
          self._socket.write(msg)

          @QtCore.Slot()
          def on_readyRead(self):
          print("Response: ", self._socket.readAll())

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)
          address = '127.0.0.1'
          port = 9000
          server = ClientManager()
          server.launch(address, port)
          sys.exit(app.exec_())





          share|improve this answer













          First of all the state that signals is ConnectingState that indicates that the connection has not been made so it is not correct to perform any task at that moment, you must wait for the status to be ConnectedState. On the other hand, the port you point out is probably being used by another application since it is a small number that are usually reserved for another task. In the next part I show an example of a server and a client (first launch the server and then you can launch the number of clients you want.). Finally in Qt the tasks should not be performed synchronously but through signals since the Qt event-loop needs to update internal and external variables states.



          server.py



          import uuid
          from PySide import QtCore, QtNetwork

          class ServerManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ServerManager, self).__init__(parent)
          self._server = QtNetwork.QTcpServer(self)
          self._server.newConnection.connect(self.on_newConnection)
          self._clients = {}

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._server.listen(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot()
          def on_newConnection(self):
          socket = self._server.nextPendingConnection()
          socket.readyRead.connect(self.on_readyRead)
          if socket not in self._clients:
          self._clients[socket] = uuid.uuid4()

          @QtCore.Slot()
          def on_readyRead(self):
          socket = self.sender()
          resp = socket.readAll()
          code = self._clients[socket]
          print("From[{}]- message: {}".format(code, resp))
          socket.write("Server: " + str(resp)[::-1])

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)

          address = '127.0.0.1'
          port = 9000
          server = ServerManager()
          if not server.launch(address, port):
          sys.exit(-1)
          sys.exit(app.exec_())


          client.py



          from PySide import QtCore, QtNetwork

          class ClientManager(QtCore.QObject):
          def __init__(self, parent=None):
          super(ClientManager, self).__init__(parent)
          self._socket = QtNetwork.QTcpSocket(self)
          self._socket.stateChanged.connect(self.on_stateChanged)
          self._socket.readyRead.connect(self.on_readyRead)
          self._timer = QtCore.QTimer(self, interval=1000)
          self._timer.timeout.connect(self.sendMessage)

          def launch(self, address=QtNetwork.QHostAddress.Any, port=9999):
          return self._socket.connectToHost(QtNetwork.QHostAddress(address), port)

          @QtCore.Slot(QtNetwork.QAbstractSocket.SocketState)
          def on_stateChanged(self, state):
          if state == QtNetwork.QAbstractSocket.ConnectedState:
          self._timer.start()
          print("connected")
          elif state == QtNetwork.QAbstractSocket.UnconnectedState:
          print("disconnected")
          QtCore.QCoreApplication.quit()

          @QtCore.Slot()
          def sendMessage(self):
          if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
          msg = QtCore.QDateTime.currentDateTime().toString()
          self._socket.write(msg)

          @QtCore.Slot()
          def on_readyRead(self):
          print("Response: ", self._socket.readAll())

          if __name__ == '__main__':
          import sys
          import signal
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QtCore.QCoreApplication(sys.argv)
          address = '127.0.0.1'
          port = 9000
          server = ClientManager()
          server.launch(address, port)
          sys.exit(app.exec_())






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 20:33









          eyllanesceyllanesc

          79.8k103258




          79.8k103258













          • Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

            – mikanim
            Nov 20 '18 at 22:01











          • @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

            – eyllanesc
            Nov 20 '18 at 22:02











          • @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

            – eyllanesc
            Nov 20 '18 at 22:41



















          • Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

            – mikanim
            Nov 20 '18 at 22:01











          • @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

            – eyllanesc
            Nov 20 '18 at 22:02











          • @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

            – eyllanesc
            Nov 20 '18 at 22:41

















          Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

          – mikanim
          Nov 20 '18 at 22:01





          Thanks for the comment. How long should I have to wait after running connectToHost() for it to finally be connected? It was in the ConnectingState quite some time.

          – mikanim
          Nov 20 '18 at 22:01













          @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

          – eyllanesc
          Nov 20 '18 at 22:02





          @mikanim That depends on many variables such as network, hardware, etc. so there is no answer for that. The correct thing is to use the signals as I have shown in my example.

          – eyllanesc
          Nov 20 '18 at 22:02













          @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

          – eyllanesc
          Nov 20 '18 at 22:41





          @mikanim Remember that Qt works asynchronously, that allows you not to worry about verifying at any moment the state of a variable like the state and you can do other tasks. If my answer helps you do not forget to mark it as correct, if you do not know how to do it then check the tour

          – eyllanesc
          Nov 20 '18 at 22:41




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392316%2fpython-qtnetwork-qtcpsocket-readall-and-qtnetwork-qtcpsocket-write-not-worki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?