Skip to content

Instantly share code, notes, and snippets.

@hartred
Created March 23, 2018 11:10
Show Gist options
  • Save hartred/ac60e3e816d850702fb7f5c7e38ce025 to your computer and use it in GitHub Desktop.
Save hartred/ac60e3e816d850702fb7f5c7e38ce025 to your computer and use it in GitHub Desktop.
Twisted SIP protocol example
from twisted.internet import reactor
from twisted.protocols import sip
from twisted.internet.protocol import ServerFactory
class SipProxy(sip.Proxy):
def __init__(self):
sip.Proxy.__init__(self,host='192.168.1.3',port=5060)
self.tries=0
def handle_request(self,message,addr):
print message.toString()
print dir(message)
if message.method=='ACK':return
r = self.responseFromRequest(301,message)
r.addHeader("Contact","sip:192.168.1.100:5061")
r.creationFinished()
self.deliverResponse(r)
print r.toString()
print addr
self.tries+=1
class sipfactory(ServerFactory):
protocol=SipProxy
reactor.listenUDP(5060,SipProxy(),'192.168.1.3')
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment