[PyQt] QtNetwork newbie question

Phil Thompson phil at riverbankcomputing.com
Sun Mar 18 21:55:06 GMT 2012


On Sun, 18 Mar 2012 13:40:49 -0700, John Stewart
<john.stewart at insomniafilm.com> wrote:
> Hi all,
> I am trying to write a distributed render manager.  The sever would be
> waiting for incoming connections (other CPUs wishing to be part of the
> machine pool) and then issue commands to be run on those other CPUs when
a
> job is run in the manager via a user.
> So far, this is what I am using to listen for connections and return
their.
> 
> class Main(QtGui.QMainWindow):
>     def __init__(self):
>         QtGui.QMainWindow.__init__(self)
> 	#init UI
>         self.ui=Ui_rndr_Manager()
>         self.ui.setupUi(self)
> 
> 	#init Network
>         self.tcpServer = QtNetwork.QTcpServer()
>         self.tcpServer.listen(address=QtNetwork.QHostAddress.Any,
>         port=5000)
>         self.connect(self.tcpServer, QtCore.SIGNAL("newConnection()"),
>         self.newConnectionArrives )
>     
>         
>     def newConnectionArrives(self):
>         self.sock = self.tcpServer.nextPendingConnection()
>         self.connect(self.sock, QtCore.SIGNAL("readyRead()"),
>         self.tcpSocketReadyReadEmitted)
>     
> 
>     def tcpSocketReadyReadEmitted(self):
>         data = str(self.sock.readAll())
>         print data
> 
> 
> When I try and have two separate clients connect, the first client is
> ignored and only the second's data is received.  Am I going about this
the
> wrong way for multiple client connections or is there just something I
am
> missing?

You are rebinding self.sock and so losing any previous connection.

Phil


More information about the PyQt mailing list