Twisted kullanarak bir istemci/sunucu oluşturmaya çalışıyorum. İstemci olarak başka bir sunucuya bağlanacak ve diğer istemciler için bir sunucu gibi davranacak bir daemon oluşturmak istiyorum. Gördüğünüz gibi, ben (bir sunucu gibi) göndermek istiyorumTwisted ile istemci/sunucu oluşturma
server = sys.argv[1]
control_port = 8001
class ControlClient(protocol.Protocol):
def makeConnection(self, transport):
[some code here -snip-]
self.firstOrder(order, transport)
def firstOrder(self, action, transport):
self.t = transport
self.t.write(action + "\0")
def sendOrder(self, action):
self.t.write(action + "\0")
def dataReceived(self, data):
[some code here -snip-]
[HERE I WANT TO SEND DATA TO CLIENTS CONNECTED TO MY TWISTED SERVER, USING CONTROL SERVER]
class ControlServer(ControlClient):
def dataReceived(self, data):
print "client said " + data
def makeConnection(self, transport):
self.t = transport
self.t.write("make connection")
print "make connection"
def sendData(self, data):
self.t.write("data")
class ClientFactory(protocol.ClientFactory):
protocol = ControlClient
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop()
class ServerFactory(protocol.ServerFactory):
protocol = ControlServer
def main():
c = ClientFactory()
reactor.connectTCP(server, control_port, c)
s = ServerFactory()
reactor.listenTCP(9000, s)
reactor.run()
if __name__ == '__main__':
main()
bazı veriler (istemci olarak) aldı: benim sorunu tarif düşünüyorum wich gibi yazma şey var. Benim sorunum elbette benim ServerControl benim ClientControl içinde örneklenmiş değildir, bu yüzden istemcilere veri göndermek için gerekli olan ulaşım için erişimim yok. Ben anlaşılabilir olmazsam
Üzgünüm, Python ve Twisted yeniyim ve İngilizce hiçbir bir şey eksik sormak için çekinmeyin :(benim ana dilidir!
Teşekkür herhangi bir yardım için şimdiden =
Merhaba, Teşekkürler bunu deneyeceğim. İyi bir çözüm gibi görünüyor. – tirlototo
Peki, yardımlarınız için teşekkürler, çok iyi çalışıyor! İyi günler =) – tirlototo
ahah bükümlü bir geliştiricisiniz; =) – tirlototo