def main(): testApp = MyTestApp() factory = EchoFactory(testApp) factory.protocol = Echo reactor = npyscreenreactor.install() PORT = 5000 reactor.listenTCP(PORT, factory) testApp.updateFields(received="Chat server started on port " + str(PORT)) reactor.registerNpyscreenApp(testApp) reactor.run()
def startedConnecting(self, connector): # print 'Started connecting' pass def buildProtocol(self, addr): # print 'Building protocol' proto = self.protocol() proto.factory = self return proto def clientConnectionLost(self, connector, reason): print 'Lost connection. Reason: %s' % reason def clientConnectionFailed(self, connector, reason): print 'Connection failed. Reason: %s' % reason if __name__ == "__main__": App = TestApp() factory = TestClientFactory(App) factory.protocol = TestProtocol reactor = npyscreenreactor.install() reactor.registerNpyscreenApp(App) reactor.connectTCP("127.0.0.1", 2000, factory) try: reactor.run() finally: reactor.stop()
#!/usr/bin/env python # vim: set tabstop=4 shiftwidth=4 expandtab ai import npyscreen from datetime import datetime # npyscreen twisted reactor import npyscreenreactor reactor = npyscreenreactor.install() # Incorporates code from #Pymodbus Asynchronous Server Example #---------------------------------------------------------------------------# # import the various server implementations #---------------------------------------------------------------------------# from pymodbus.constants import Defaults from pymodbus.transaction import ModbusSocketFramer, ModbusAsciiFramer from pymodbus.server.async import ModbusServerFactory from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSparseDataBlock from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext # for emulator code import os import sys import string