[PyQt] Having a problem with QTcpSocket

Nick Gaens nickgaens at gmail.com
Sat Nov 21 16:19:00 GMT 2009


Hello all,

I'm trying to get two clients to speak to each other, using an instance of QtNetwork.QTcpSocket for each client.
The clients are on different computers with IP's: 192.168.1.100 and .102

On the first client, I run the code below:

------------------
def __init__(self):
    self.socket = QtNetwork.QTcpSocket(self)
    self.socket.setLocalAddress(QtNetwork.QHostAddress("192.168.1.100"))
    self.socket.setLocalPort(55555)
    self.socket.readyRead.connect(self.receiveData)

def connectToOtherClient(self, ip):
    self.socket.connectToHost(QtNetwork.QHostAddress(ip), 55555)
    if self.socket.waitForConnected(10000):
        print "Connected!"
    else:
        print self.socket.state() # Prints '0' (zero), meaning UnconnectedState

------------------

So I create a QTcpSocket, I tell it the IP I want to use and after having the user asking for the remote IP address, connectToOtherClient() is invoked.

On the second client, I just create an instance of this class, using "192.168.1.102" as IP there in __init__(). No invocation of connectToOtherClient() there, ofcourse..

The problem is: it doesn't connect at all.. The socket state remains "UnconnectedState"..

What am I doing wrong here?

Wkr,

Nick Gaens




More information about the PyQt mailing list