Hi everyone,
I've developed a small application to test a connection to an asterisk server (the same connection can be tested using telnet so I know it's working ok on the server side) in my private lan but it's failing and I've run out of ideas. I'd gladly appreciate any help on this. As it's quite short I'm posting my code below.
Short note: I have to send a package that ends with 2 CRLF hence the empty string as the last line added to the arraylist.
Again thanks for any help you might give me.
public static void main(String[] args) {
try {
Socket socket = new Socket("192.168.1.5", 5038);
PrintWriter out = new PrintWriter(socket.getOutputStream(), false);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String dataIn = "";
String dataOut = "";
ArrayList data = new ArrayList();
data.add("action: login");
data.add("username: admin");
data.add("secret: password");
data.add("");
while(true) {
if(input.readLine().equalsIgnoreCase("q"))
System.exit(0);
System.out.println("ready() value: " + in.ready());
while(in.ready()) {
dataIn = in.readLine();
System.out.println("From server: " + dataIn +
" and ready() value: " + in.ready());
}
if(dataOut.equalsIgnoreCase("")) {
out.println(data.get(0));
System.out.println("To server: " + data.get(0));
out.println(data.get(1));
System.out.println("To server: " + data.get(1));
out.println(data.get(2));
System.out.println("To server: " + data.get(2));
out.println(data.get(3));
System.out.println("To server: " + data.get(3));
dataOut = "Sent!";
}
}
} catch (UnknownHostException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
P.S: if you need any more info just say so. Thanks again.
