Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

twisted

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)
like image 239
daccle Avatar asked Apr 20 '10 11:04

daccle


1 Answers

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

like image 122
Thomas Wouters Avatar answered Nov 05 '22 10:11

Thomas Wouters