Twisted: how-to bind a server to a specified IP address?

我是研究僧i 提交于 2021-02-15 11:43:56

问题


I want to have a twisted service (started via twistd) which listens to TCP/POST request on a specified port on a specified IP address. By now I have a twisted application which listens to port 8040 on localhost. It is running fine, but I want it to only listen to a certain IP address, say 10.0.0.78.

How-to manage that? This is a snippet of my code:

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)

回答1:


What you're looking for is the interface argument to twisted.application.internet.TCPServer:

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

(Which it inherits from reactor.listenTCP(), since all the t.a.i.*Server classes really just forward to reactor.listenXXX for the appropriate protocol.)



来源:https://stackoverflow.com/questions/2674799/twisted-how-to-bind-a-server-to-a-specified-ip-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!