2010-04-20 13 views
10

Desidero avere un servizio twistato (avviato tramite twistd) che ascolta la richiesta TCP/POST su una porta specificata su un indirizzo IP specificato. Ormai ho un'applicazione contorta che ascolta la porta 8040 su localhost. Funziona bene, ma voglio solo ascoltare un determinato indirizzo IP, ad esempio 10.0.0.78.Intrecciato: come associare un server a un indirizzo IP specificato?

Come gestirlo? Si tratta di un frammento del mio codice:

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) 

risposta

13

Quello che stai cercando è la interface argomento per twisted.application.internet.TCPServer:

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

(che eredita da reactor.listenTCP(), dal momento che tutte le classi t.a.i.*Server in realtà solo andata a reactor.listenXXX per il protocollo appropriato.)

Problemi correlati