I created a server with a custom protocol using Twisted and I have clients that connect to the server on a specific port (say port 1234). I am looking to create a control interface for the server based on a web page of some sort. My research so far indicated Nevow is popular choice but I only need something very simple.
Say for example, every time a browser accesses the hello world page on port 8080, I send a message to clients connected on 1234.
I am a bit confused as to how I can connect these 2 together. I assume I would need to call Server.message from HelloResource.render_GET ?
from twisted.internet import protocol, reactor
from twisted.web.resource import Resource
class Server(protocol.Protocol):
def dataReceived(self, data):
#do something on the server side
def message(self)
#send message to clients
class HelloResource(Resource):
isLeaf = True
def render_GET(self,request):
return "<html>Hello, world!</html>"
factory = protocol.Factory()
factory.protocol = Server
reactor.listenTCP(1234, factory)
reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()