如何解决使用 Twisted 实现 SIP 重定向
我正在寻找更多关于使用 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 举报,一经查实,本站将立刻删除。