im new for python and im looking for a way to send data from server to client. I have a server monitoring program running on a server and you want to send a notification via python server to a python client
this is server code
from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor import time class Server(Protocol): def connectionMade(self): self.transport.write("data to client") factory = Factory() factory.protocol = Server reactor.listenTCP(8789, factory) reactor.run()
Client code
from twisted.internet.protocol import Protocol, ClientFactory from sys import stdout from twisted.internet import reactor class printData(Protocol): def dataReceived(self, data): stdout.write(data) class ClientFactory(ClientFactory): def startedConnecting(self, connector): print 'connecting' def buildProtocol(self, addr): print 'Connected.' return printData() def clientConnectionLost(self, connector, reason): print reason def clientConnectionFailed(self, connector, reason): print reason if __name__ == '__main__': reactor.connectTCP('localhost', 8789, ClientFactory()) reactor.run()
so far I have found that if the client sends a message, the server responds to this message, but is there a way to send data only when the data is available to the client, without waiting for the clients to respond?
source share