private void checkIfAsteriskRunning ( AsteriskSettings asteriskSettings ) throws UnknownHostException , IOException { try ( Socket socket = new Socket ( ) ) { socket . setSoTimeout ( 2000 ) ; InetSocketAddress asteriskHost = new InetSocketAddress ( asteriskSettings . getAsteriskIP ( ) , asteriskSettings . getManagerPortNo ( ) ) ; socket . connect ( asteriskHost , 2000 ) ; } }
This method will try to make a simple tcp connection to the asterisk manager to establish it is up . We do this as the default makeConnection doesn t have a timeout and will sit trying to connect for a minute or so . By using method when the user realises they have a problem on start up they can go to the asterisk panel . Fix the problem and then we can retry with the new connection settings within a couple of seconds rather than waiting a minute for a timeout .