我在服务器上设置了Asterisk。
我设置了基本的“Hello,World”示例(直接来自文档here),其中包含我的extensions.conf
文件:
[from-internal]
exten = 100,1,Answer()
same = n,Wait(1)
same = n,Playback(hello-world)
same = n,Hangup()
和我的pjsip.conf
文件:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
[6001]
type=endpoint
context=from-internal
disallow=all
allow=ulaw
auth=6001
aors=6001
[6001]
type=auth
auth_type=userpass
password=unsecurepassword
username=6001
[6001]
type=aor
max_contacts=1
我有一个简单的Python脚本来调用扩展程序100.这是直接来自文档here,我在这里调用此脚本传入sip地址sip:100@<my-sip-server-ip>
:
import sys
import pjsua as pj
# Logging callback
def log_cb(level, str, len):
print str,
# Callback to receive events from Call
class MyCallCallback(pj.CallCallback):
def __init__(self, call=None):
pj.CallCallback.__init__(self, call)
# Notification when call state has changed
def on_state(self):
print "Call is ", self.call.info().state_text,
print "last code =", self.call.info().last_code,
print "(" + self.call.info().last_reason + ")"
# Notification when call's media state has changed.
def on_media_state(self):
global lib
if self.call.info().media_state == pj.MediaState.ACTIVE:
# Connect the call to sound device
call_slot = self.call.info().conf_slot
lib.conf_connect(call_slot, 0)
lib.conf_connect(0, call_slot)
print "Hello world, I can talk!"
# Check command line argument
if len(sys.argv) != 2:
print "Usage: simplecall.py <dst-URI>"
sys.exit(1)
try:
# Create library instance
lib = pj.Lib()
# Init library with default config
lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
# Create UDP transport which listens to any available port
transport = lib.create_transport(pj.TransportType.UDP)
# Start the library
lib.start()
# Create local/user-less account
acc = lib.create_account_for_transport(transport)
# Make call
call = acc.make_call(sys.argv[1], MyCallCallback())
# Wait for ENTER before quitting
print "Press <ENTER> to quit"
input = sys.stdin.readline().rstrip("\r\n")
# We're done, shutdown the library
lib.destroy()
lib = None
except pj.Error, e:
print "Exception: " + str(e)
lib.destroy()
lib = None
sys.exit(1)
一切正常,我打电话给SIP服务器,听到“Hello,World”录音。
我需要更改哪些内容才能通过TCP进行此通信?
到目前为止,我已经尝试通过在以下部分中将协议更改为tcp来更改我的pjsip.conf
文件:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
,将;transport=tcp
添加到我传入Python脚本的服务器的URI中,并更改Python脚本中创建传输的行
# Create UDP transport which listens to any available port
transport = lib.create_transport(pj.TransportType.UDP)
我得到的Python脚本会发生什么
pjsua_acc.c !...SIP registration failed, status=408 (Request Timeout)
在服务器上我根本看不到请求。
答案 0 :(得分:0)
你确定你的Asterisk正在使用pjsip吗?旧版本(低于v.11)使用的是sip.conf而不是pjsip.conf。
您需要在 sip.conf :
中全局启用tcp[general]
tcpenable=yes
tcpbindaddr=0.0.0.0
如果您使用的是新的Asterisk,请将其添加到 pjsip.conf :
[transport-tcp]
type=transport
protocol=tcp
bind=0.0.0.0:5060
[transport-tcp-out]
type=transport
protocol=tcp
bind=0.0.0.0:5060
#local_net=192.168.X.X/XX //you might also set this