Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQT4 Asynchronous QTcpServer (How to create event loop)
    primarykey
    data
    text
    <p>Trying to convert a server written in C++ into Python. The server was written to be Asynchronous/Non Blocking. What works in C++ doesn't seem to want to work for me in Python</p> <p>I am using PyQT4. I read Python you have to create the event loop or something along those lines any ideas are greatly appreciated</p> <p>I should mention what seems to not work is that the <strong>incomingConnection</strong> function in Class Server is never called. </p> <p>*cheers</p> <pre><code>import sys from PyQt4.QtCore import * from PyQt4.QtNetwork import * class Client(QObject): def __init__(self, parent=None): QObject.__init__(self) QThreadPool.globalInstance().setMaxThreadCount(15) def SetSocket(self, Descriptor): self.socket = QTcpSocket(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.setSocketDescriptor(Descriptor) print "Client Connected from IP %s" % self.socket.peerAddress().toString() def connected(self): print "Client Connected Event" def disconnected(self): print "Client Disconnected" def readyRead(self): msg = self.socket.readAll() print msg class Server(QObject): def __init__(self, parent=None): QObject.__init__(self) def incomingConnection(self, handle): print "incoming" self.client = Client(self) self.client.SetSocket(handle) def StartServer(self): self.server = QTcpServer() if self.server.listen(QHostAddress("0.0.0.0"), 8888): print "Server is awake" else: print "Server couldn't wake up" def main(): app = QCoreApplication(sys.argv) Server().StartServer() sys.exit(app.exec_()) if __name__ == '__main__': main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload