from hendrix.contrib.async.messaging import hxdispatcher from hendrix.deploy.base import HendrixDeploy from txsockjs.factory import SockJSResource from hendrix.contrib.async.resources import MessageHandlerProtocol from hendrix.facilities.resources import NamedResource from twisted.internet.protocol import Factory message_resource = NamedResource('hendrix-demo') message_resource.putChild('messages', SockJSResource(Factory.forProtocol(MessageHandlerProtocol))) from twisted.conch.telnet import TelnetTransport, TelnetProtocol from twisted.internet.protocol import ServerFactory class TelnetToWebsocket(TelnetProtocol): def dataReceived(self, data): hxdispatcher.send('noodly_messages', data) telnet_server_factory = ServerFactory() telnet_server_factory.protocol = lambda: TelnetTransport(TelnetToWebsocket) deployer = HendrixDeploy(options={'wsgi': 'hendrix_demo.wsgi.application'}) deployer.resources.append(message_resource) deployer.reactor.listenTCP(6565, telnet_server_factory) deployer.run()
raise self.dispatcher.send( self.guid, {'message': data, 'error': str(exc)} ) def connectionMade(self): """ establish the address of this new connection and add it to the list of sockets managed by the dispatcher reply to the transport with a "setup_connection" notice containing the recipient's address for use by the client as a return address for future communications """ self.transport.uid = str(uuid.uuid1()) self.guid = self.dispatcher.add(self.transport) self.dispatcher.send(self.guid, {'setup_connection': self.guid}) def connectionLost(self, something): "clean up the no longer useful socket in the dispatcher" self.dispatcher.remove(self.transport) MessageResource = NamedResource('messages') MessageResource.putChild( 'main', SockJSResource(Factory.forProtocol(MessageHandlerProtocol)) )
def setUp(self): path = '/path/to/child/' self.res = NamedResource(path) self.hr = HendrixResource(None, None, None) self.hr.putNamedChild(self.res)
except Exception, exc: raise self.dispatcher.send(self.guid, { 'message': data, 'error': str(exc) }) def connectionMade(self): """ establish the address of this new connection and add it to the list of sockets managed by the dispatcher reply to the transport with a "setup_connection" notice containing the recipient's address for use by the client as a return address for future communications """ self.transport.uid = str(uuid.uuid1()) self.guid = self.dispatcher.add(self.transport) self.dispatcher.send(self.guid, {'setup_connection': self.guid}) def connectionLost(self, something): "clean up the no longer useful socket in the dispatcher" self.dispatcher.remove(self.transport) MessageResource = NamedResource('messages') MessageResource.putChild( 'main', SockJSResource(Factory.forProtocol(MessageHandlerProtocol)))
self.dispatcher.send(address, data) except Exception as e: raise self.dispatcher.send( self.guid, {'message': data, 'error': str(e)} ) def connectionMade(self): """ establish the address of this new connection and add it to the list of sockets managed by the dispatcher reply to the transport with a "setup_connection" notice containing the recipient's address for use by the client as a return address for future communications """ self.transport.uid = str(uuid.uuid1()) self.guid = self.dispatcher.add(self.transport) self.dispatcher.send(self.guid, {'setup_connection': self.guid}) def connectionLost(self, something): "clean up the no longer useful socket in the dispatcher" self.dispatcher.remove(self.transport) MessageResource = NamedResource('messages')