[Asterisk-java-users] Solution to "Connection refused" exception (was: Re: asterisk-java integrati
Brought to you by:
srt
From: Stefan R. <sr...@re...> - 2005-10-20 11:33:51
|
Just for the archives and anybody who might encounter a similar problem i= n the future: > The problem i was having was that the connection was refused. [...] > ******************************* > Here is the error message from java: > ******************************* > Oct 19, 2005 2:19:03 AM net.sf.asterisk.util.impl.JavaLoggingLog info > INFO: Connecting to localhost port 5038 > java.net.ConnectException: Connection refused > at java.net.PlainSocketImpl.socketConnect(Native Method) > at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) > at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:1= 71) [...] > ******************************* > telnet from another console > ******************************* > cm@laptop:~> telnet 127.0.0.1 5038 > Trying 127.0.0.1... > Connected to 127.0.0.1. > Escape character is '^]'. > Asterisk Call Manager/1.0 so using telnet worked but using the Manager API via Asterisk-Java did no= t. After some investigation it turned out that the cause of this strange behaviour was that the Asterisk-Java code tried to connect to 'localhost'= . Given the following in /etc/hosts (the default for SuSE Linux): 127.0.0.1 localhost # special IPv6 addresses ::1 localhost ipv6-localhost ipv6-loopback localhost could resolve to either 127.0.0.1 or ::1. As Asterisk does not yet support IPV6 out of the box the Manager API is only available on 127.0.0.1 and not on ::1. Asterisk-Java currently does not try to connect to every IP that a hostname may resolve to. So whenever 'localhost' resolved to ::1 it cause= d a connection refused. The solution to this problem is to change /etc/hosts to something like: 127.0.0.1 localhost # special IPv6 addresses ::1 ipv6-localhost ipv6-loopback i.e. mapping localhost only to 127.0.0.1. Another option is to comment out the ::1 completely (if you dont need it for any other purposes). =3DStefan |