[PyQt] QtNetwork newbie question

John Stewart john.stewart at insomniafilm.com
Mon Mar 19 19:22:09 GMT 2012


Thanks Phil,
So my first thought was to try not binding the nextPendingConnection() which looks like this:

self.connect(self.tcpServer.nextPendingConnection(), QtCore.SIGNAL("readyRead()"), self.tcpSocketReadyReadEmitted)

But then how do access the readAll() for the data thats being sent?  Doing the same bit on the tcpSocketReadyReadEmitted function throws an AttributeError.

def tcpSocketReadyReadEmitted(self):
	data = str( self.tcpServer.nextPendingConnection().readAll() )
	print data

returns

AttributeError: 'NoneType' objet has no attribute 'readAll'


Again, total beginner at this so sorry if the answer is glaring.

Cheers,
John



On Mar 18, 2012, at 2:55 PM, Phil Thompson wrote:

> 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