python - Why is there no content when calling readAll in a Qtcpsocket's readyRead callback? -


i building minimal socket server display window when receives message.

the server uses newconnection signal client connections , connect proper signals (connected, disconnected , readyread) each socket.

when running server program, , sending data proper address, each datum sent, qtcpsocket connected, readyread, disconnected. , within readyread callback, readall return nothing. (i suppose cause of disconnected signal).

still, client gets no "broken pipe error" , can continue send data.

how can happen ?

here's code :

class client(qobject):     def connects(self):         self.connect(self.socket, signal("connected()"), slot(self.connected()))         self.connect(self.socket, signal("disconnected()"), slot(self.disconnected()))         self.connect(self.socket, signal("readyread()"), slot(self.readyread()))         self.socket.error.connect(self.error)         print "client connected ip %s" % self.socket.peeraddress().tostring()      def error(self):         print "error somewhere"      def connected(self):         print "client connected event"      def disconnected(self):         self.readyread()         print "client disconnected"      def readyread(self):         print "reading"         msg = self.socket.readall()         print qstring(msg), len(msg)         n = notification(qstring(msg))         n.show()  class server(qobject):     def __init__(self, parent=none):         qobject.__init__(self)         self.clients = []      def setup_client_socket(self):         print "incoming"         client = client(self)         client.socket = self.server.nextpendingconnection()         #self.client.socket.nextblocksize = 0         client.connects()         self.clients.append(client)      def startserver(self):         self.server = qtcpserver()         self.server.listen(qhostaddress.localhost, 8888)         print self.server.islistening(), self.server.serveraddress().tostring(), self.server.serverport()         self.server.newconnection.connect(self.setup_client_socket) 

update : tested directly socket module python standard lib , works. general setup of machine , network not guilty parties there. qt issue.

the slot function expects string representing name of slot, , should preceded target of slot:

self.connect(self.socket, signal("connected()"), self, slot("connected()")) 

but without quotes, making immediate call function connect line is. didn't declare these functions slots using qtcore.slot/pyqtslot decorator, wouldn't called anyway when signals emitted, if use slot function.

for undecorated python functions, should use 1 of these syntaxes:

self.connect(self.socket, signal("connected()"), self.connected) 

or

self.socket.connected.connect(self.connected) 

notice lack of () @ end of last parameter.

additionally shouldn't call readyread in disconnected, if there data read before disconnection, readyread function called.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -