【问题标题】:Twisted: how-to bind a server to a specified IP address?Twisted:如何将服务器绑定到指定的 IP 地址?
【发布时间】:2010-04-20 11:53:40
【问题描述】:

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

如何管理?这是我的代码的 sn-p:

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)

【问题讨论】:

    标签: python twisted


    【解决方案1】:

    您正在寻找的是 interfacetwisted.application.internet.TCPServer 的参数:

    smsInboundServer = internet.TCPServer(8001, webserver.Site(smsInbound),
        interface='10.0.0.78')
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-02
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2017-01-23
      • 2021-01-20
      • 1970-01-01
      相关资源
      最近更新 更多