python - Create client/server with Twisted -


I am trying to create a client / server using Twisted I want to create a daemon, Will be linked to another server and will serve as the server for other clients. I wrote something that I think is describing my problem:

  server = sys.argv [1] control_port = 8001 class ControlClient (protocol): def makeConnection (auto, Transportation): [Some code here-snip-] self.firstOrder (order, transport) DEF First order (self, action, transport): self.t = transport self.t.write (action + "\ 0") send DEF Order (self, action): self. Received TRET (Action + "\ 0") DIF Data (self, data): [Some code here - snip-] [Here I want to send data to clients connected to my broken server, use control server] Class control Server (control client): DIF data received (self, data): printed "client said" + data DEF defConnection (self, transport): self.t = transport self.t.write ("make connection") print "connection Create "def sendData (self, data): self.t.wri Te ("data") class ClientFactory (protocol.ClientFactory): Protocol = ControlClient def clientConnectionFailed (auto, connector, reason): Print "Connection Failed - Bye!" Reactor.stop () DIF Client ConnectiveList (Self, Connector, Reason): Print "Connection Lost - Bye!" Reactor.stop () class serverfinery (protocol. Serverfacture): protocol = controllerdef main (): c = clientfichre () reactor.connect tcp (server, control_port, c) s = serverfacture () reactor.listen TCP (9000, s) ) Reactor .run () If __name__ == '__main__': main ()   

As you can see, I want to get some data (as a server) As a customer) My problem is definitely that my server control has not been started on my client control so I do not have access to transport, it is necessary to send data to customers.

Sorry, if I can not understand, then I am new Python and twisted and I do not have any main language in English: (Feel free to remember if you miss something!

Thanks in advance for any help =)

The only thing you are missing That is, you can keep a list of your client connections and make that list available for the code that is trying to send data to all Laints.

Turn one of these examples into an example:

In that example there is only one factory, but this idea is similar. To handle your case with two factories, refer only to one factory to another.

Comments