我正在尝试使用Asterisk服务器进行身份验证,但我收到了以下错误:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at net.sf.asterisk.io.impl.SocketConnectionFacadeImpl.<init> SocketConnectionFacadeImpl.java:52)
at net.sf.asterisk.manager.DefaultManagerConnection.createSocket(DefaultManagerConnection.java:541)
at net.sf.asterisk.manager.DefaultManagerConnection.connect(DefaultManagerConnection.java:530)
at net.sf.asterisk.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:418)
at net.sf.asterisk.manager.DefaultManagerConnection.login(DefaultManagerConnection.java:377)
at call.HelloManager.run(HelloManager.java:48)
at call.HelloManager.main(HelloManager.java:66)
这是我的代码:
public class HelloManager
{
private ManagerConnection managerConnection;
public HelloManager() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory();
this.managerConnection = factory.getManagerConnection(host, port,
user, password);
}
public void run() throws IOException, AuthenticationFailedException,
TimeoutException
{
OriginateAction originateAction;
ManagerResponse originateResponse;
originateAction = new OriginateAction();
originateAction.setChannel(" SIP/2.0/UDP");
originateAction.setContext("default");
originateAction.setExten("101");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Integer(30000));
// connect to Asterisk and log in
managerConnection.login();
// send the originate action and wait for a maximum of 30 seconds for Asterisk
// to send a reply
// originateResponse = managerConnection.sendAction(originateAction, 30000);
// // print out whether the originate succeeded or not
// System.out.println(originateResponse.getResponse());
// and finally log off and disconnect
// managerConnection.logoff();
}
public static void main(String[] args) throws Exception
{
HelloManager helloManager;
helloManager = new HelloManager();
helloManager.run();
}
}
有人能帮我解决这个问题吗?
您需要检查/etc/asteirsk/manger.conf 中的设置
最喜欢的是,它绑定到127.0.0.1地址或完全禁用。
也可能是防火墙(本地或远程)的问题,端口5038 tcp已被允许。