tags:

views:

92

answers:

1

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  A: 

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.)

Thomas Wouters
Thank you! That solves my problem. It works fine.
daccle