Note that there are some explanatory texts on larger screens.

plurals
  1. POtwisted transport.write in a non-reactor thread
    primarykey
    data
    text
    <p>I am designing a gui application as a client for a server where i have 3 classes</p> <p>a class for twisted protocol , another for the factory and the third for the pyqt thread it self. how can i send data from the pyqt thread , as example if a button was clicked how can i send a command using the current twisted connection, here is a copy of my codes</p> <pre><code>from OpenSSL import SSL;import sys from twisted.internet.protocol import ClientFactory from twisted.internet import ssl, protocol from PyQt4 import QtCore, QtGui from gui import Ui_clientgui class clientgui(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_clientgui() self.ui.setupUi(self) def closeEvent(self, e): try:reactor.callFromThread(reactor.stop) except:pass class Client(protocol.Protocol): def connectionMade(self): global server_options server_options['connection'] = True def send(self,data): self.transport.write(data) def connectionLost(self, reason): server_options['connection'] = False def dataReceived(self, line): print "receive:", line class ClientFactory(ClientFactory): protocol = Client def clientConnectionFailed(self, connector, reason): print 'connection failed' try:reactor.stop() except:pass if __name__ == '__main__': app = QtGui.QApplication([]) import qt4reactor qt4reactor.install() from twisted.internet import reactor factory = ClientFactory() reactor.connectSSL('localhost', 8080, factory, ssl.ClientContextFactory()) application = clientgui(reactor) application.show() reactor.runReturn() sys.exit(app.exec_()) </code></pre>
    singulars
    1. This table or related slice is empty.
    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