twisted - 服务器与服务器之间的通信扭曲

标签 twisted

这是与 echoserver 通信的 echoclient 代码:

from twisted.internet import protocol, reactor

class Echo(protocol.Protocol):
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()


reactor.listenTCP(8000, EchoFactory())
reactor.run()

这是回声器:
from twisted.internet import reactor, protocol

class EchoClient(protocol.Protocol):
    def connectionMade(self):
        self.transport.write("Hello, world!")
        def dataReceived(self, data):
        print "Server said:", data
        self.transport.loseConnection()

class EchoFactory(protocol.ClientFactory):
    def buildProtocol(self, addr):
        return EchoClient()
    def clientConnectionFailed(self, connector, reason):
        print "Connection failed."
        reactor.stop()
    def clientConnectionLost(self, connector, reason):
         print "Connection lost."
         reactor.stop()

 reactor.connectTCP("localhost", 8000, EchoFactory())
 reactor.run()

上面的 echoserve 和 echoclient 相互通信,但我想要服务器到服务器的通信,所以这里其他 echoserver 来了并与第一个 echoserver 通信。

最佳答案

您需要构建一个代理客户端并将其附加到其中一台服务器。并通过代理客户端与其他服务器通信。

关于twisted - 服务器与服务器之间的通信扭曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41439791/

相关文章:

python - Twisted 记录器可以以 UTC 登录吗?

用于硬件控制的 Python 服务器(可能带有 Twisted?)

python - 如何告诉 Twisted http 服务器忽略索引文件

python - 使用 Twisted 运行并返回 shell 命令的输出(查找)

python - 如何在 Twisted 中使用多个参数生成进程?

python - 为什么我们需要使用rabbitmq

python - 关于扭曲文档

python - 如何发送正在使用 Python 的 Twisted.web 实时转码的视频文件?

python 扭曲的简单客户端-服务器通信

python - 如何设置ProxyAgent的超时时间?