Twisted:如何将服务器绑定到指定的IP地址?

dac*_*cle 10 python twisted

我希望有一个扭曲的服务(通过twistd启动),它监听指定IP地址上指定端口上的TCP/POST请求.到目前为止,我有一个扭曲的应用程序,它侦听localhost上的端口8040.它运行正常,但我希望它只收听某个IP地址,比如10.0.0.78.

怎么管理?这是我的代码片段:

application = service.Application('SMS_Inbound')

smsInbound = resource.Resource()
smsInbound.putChild('75sms_inbound',ReceiveSMS(application))
smsInboundServer = internet.TCPServer(8001, webserver.Site(smsInbound))
smsInboundServer.setName("SMS Handling")
smsInboundServer.setServiceParent(application)
Run Code Online (Sandbox Code Playgroud)

Tho*_*ers 13

您正在寻找的是以下interface论点twisted.application.internet.TCPServer:

smsInboundServer = internet.TCPServer(8001, webserver.Site(smsInbound),
    interface='10.0.0.78')
Run Code Online (Sandbox Code Playgroud)

(它继承自哪个类reactor.listenTCP(),因为所有的t.a.i.*Server类实际上只是转发到reactor.listenXXX适当的协议.)