If you want to do things this way, your Server.message
obviously has to be a @classmethod
, and it has to have access to a list of clients, and send the message to each of them.
Something like this:
class Server(protocol.Protocol):
clients = set()
def dataReceived(self, data):
#do something on the server side
pass
def connectionMade(self):
Server.clients.add(self)
def connectionLost(self):
Server.clients.remove(self)
@classmethod
def message(cls):
for client in cls.clients:
client.transport.write('got GET request\n')
Now you can just call Server.message()
from your render_GET
method.
I'm not sure this is the best design—really, there are all kinds of better objects to hang a list of clients on than the protocol class—but it should work.