Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 侦听多个扭曲端点_Python_Twisted - Fatal编程技术网

Python 侦听多个扭曲端点

Python 侦听多个扭曲端点,python,twisted,Python,Twisted,我有多个服务器端点使用相同的协议和工厂监听不同的端口 我怎么知道哪一个先接通了 endpoint1 = TCP4ServerEndpoint(reactor, 8007) endpoint.listen(QOTDFactory()) endpoint2 = TCP4ServerEndpoint(reactor, 8008) endpoint2.listen(QOTDFactory()) 诸如此类……您无法区分它们之间的区别,因为您构建的对象完全相同。如果你想区别一下,考虑一下: endpoin

我有多个服务器端点使用相同的协议和工厂监听不同的端口

我怎么知道哪一个先接通了

endpoint1 = TCP4ServerEndpoint(reactor, 8007)
endpoint.listen(QOTDFactory())
endpoint2 = TCP4ServerEndpoint(reactor, 8008)
endpoint2.listen(QOTDFactory())

诸如此类……

您无法区分它们之间的区别,因为您构建的对象完全相同。如果你想区别一下,考虑一下:

endpoint1 = TCP4ServerEndpoint(reactor, 8007)
endpoint.listen(QOTDFactory("tweedledee"))
endpoint2 = TCP4ServerEndpoint(reactor, 8008)
endpoint2.listen(QOTDFactory("tweedledum"))

然后,在
QOTDFactory.buildProtocol
中,您可以轻松打印出您的工厂是
tweedledee
还是
tweedledum

对不起,我来晚了一点,假设我将一个反应器传递到侦听函数,它会立即尝试连接吗?我不确定您的意思<代码>IStreamServerEndpoint.listen不接受
reactor
参数。什么都没有,我浏览了关于twistedmatrix的教程,当时我正在考虑reactor.run。