On Mon, 23 Nov 2009 19:39:36 +0100, Nick Gaens <[email protected]> wrote: > Hans-Peter Jansen schreef: > On Monday 23 November 2009, 15:19:06 Nick Gaens wrote: > > Hans-Peter Jansen schreef: > > [...] > > ---------------------------- > def __init__(self): > self.server = QtNetwork.QTcpServer(self) > self.server.serverPort = 55555 > self.server.newConnection.connect(self.clientConnecting) > self.server.listen() # defaults to QHostAddress.Any > > def clientConnecting(self): # used by the "server" > if self.server.hasPendingConnections(): > connectingClient = > self.server.nextPendingConnection() > > connectingClient.readyRead.connect(self.receiveData) > > def connectToClient(self, ip): # used by the "client" > socket = QtNetwork.QTcpSocket() > socket.readyRead.connect(self.receiveData) > socket.connectToHost(QtNetwork.QHostAddress(ip), 55555) # > ip of > server if socket.waitForConnected(5000): > print "Connected!" > ---------------------------- > > [...] > > How odd that I receive this mail *the moment* my code started working > :-P. > > I found that the serverPort may not be overwritten. > > I removed this assignment: > > self.server.serverPort = 55555 > > Assigning properties this way usually won't work in PyQt (although Phil > tackles this already). > > try this: > self.server.listen(QtNetwork.QHostAddress.Any, 55555) > > and the clients now can connect to the server w/o any problem.. Downside > is that the port is random.. > > Pete > > _______________________________________________ > PyQt mailing list [email protected] [1] > http://www.riverbankcomputing.com/mailman/listinfo/pyqt [2] > > Hmm.. That doesn't seem to work :-S.. > > self.server.listen(QtNetwork.QHostAddress.Any, 55555): > TypeError: argument 1 of QTcpServer.listen() has an invalid > type > > How can this be? I've got PyQt4.6.2 on WinXP, Python 2.6.4
It should be... self.server.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any), 55555) Phil _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
