问题描述
我正在寻找更多关于使用 Twisted 实现 SIP 重定向服务器的意见。
from twisted.protocols.sip import Proxy,MessagesParser
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
class SIPProxy(Proxy):
def handle_request(self,message,addr):
print(message.toString())
self.deliverResponse(self.responseFromrequest(100,message))
self.deliverResponse(self.responseFromrequest(302,message))
class SIPFactory(ServerFactory):
protocol = SIPProxy('192.168.8.187',5060)
print('In Factory')
reactor.listenUDP(5060,SIPFactory())
reactor.run()
------------------OUTPUT------------------
Traceback (most recent call last):
File "twisted_service.py",line 21,in <module>
reactor.listenUDP(5060,SIPFactory())
File "/usr/local/lib64/python3.7/site-packages/twisted/internet/posixbase.py",line 439,in listenUDP
p.startListening()
File "/usr/local/lib64/python3.7/site-packages/twisted/internet/udp.py",line 185,in startListening
self._connectToProtocol()
File "/usr/local/lib64/python3.7/site-packages/twisted/internet/udp.py",line 223,in _connectToProtocol
self.protocol.makeConnection(self)
AttributeError: 'SIPFactory' object has no attribute 'makeConnection'
玩了一会后,这似乎有效,但不确定这是否是生产应用程序的正确方法
from twisted.protocols.sip import Proxy,MessagesParser
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
class SIPProxy(Proxy):
Proxy.debug = True
def handle_request(self,addr):
print(message.toString())
if message.method == 'INVITE':
self.deliverResponse(self.responseFromrequest(100,message))
self.deliverResponse(self.responseFromrequest(302,message))
reactor.listenUDP(5060,SIPProxy('192.168.8.187',5060))
reactor.run()
现在我有以下疑问:
- 看来 Proxy class 不能与 TCP 一起使用,我必须为它编写额外的代码吗?
- 对 TCP 执行此操作的正确方法是什么?
- 除了日志记录/错误处理之外,如果我想将其用于生产,还有其他任何事情/提示/建议。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)