package net.commotionwireless.olsrinfo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class OlsrInfo {

	String host = "127.0.0.1";
	int port = 2006;

	public OlsrInfo() {
	}

	public OlsrInfo(String sethost) {
		host = sethost;
	}

	public OlsrInfo(String sethost, int setport) {
		host = sethost;
		port = setport;
	}

	public String request(String req) throws IOException {
		Socket sock = null;
		BufferedReader in = null;
		PrintWriter out = null;
		String output = "";

		try {
			sock = new Socket(host, port);  
			in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
			out = new PrintWriter(sock.getOutputStream(), true);
		} catch (UnknownHostException e) {
			throw new IOException();
		} catch (IOException e) {
			System.err.println("Couldn't get I/O for socket to " + host + ":" + Integer.toString(port));
		}
		out.println("/all");
		String line;
		while((line = in.readLine()) != null) {
			output = output + line + "\n";
		}
		// the txtinfo plugin drops the connection once it outputs
		out.close();
		in.close();
		sock.close();

		return output;
	}

	public static void main (String[] args) throws IOException {
		OlsrInfo txtinfo = new OlsrInfo();
		try {
			System.out.println(txtinfo.request("/all"));
		} catch (IOException e) {
			System.err.println("Couldn't get I/O for socket to " + txtinfo.host + ":" + Integer.toString(txtinfo.port));
		}
	}
}

@@ -217,16 +217,67 @@
 eption;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A
 %0A%0Apublic
@@ -522,24 +522,26 @@
 ublic String
+%5B%5D
  request(Str
@@ -652,26 +652,54 @@
 ;%0A%09%09
+List%3C
 String
- output = %22%22
+%3E retlist = new ArrayList%3CString%3E()
 ;%0A%0A%09
@@ -1151,37 +1151,25 @@
 %0A%09%09%09
-output = output + line + %22%5Cn%22
+retlist.add(line)
 ;%0A%09%09
@@ -1286,22 +1286,59 @@
 %09return 
-output
+retlist.toArray(new String%5Bretlist.size()%5D)
 ;%0A%09%7D%0A%0A%09p
@@ -1449,27 +1449,24 @@
 %0A%09%09%09
-System.out.println(
+for (String s : 
 txti
@@ -1484,16 +1484,43 @@
 (%22/all%22)
+ )%0A%09%09%09%09System.out.println(s
 );%0A%09%09%7D c

convert request return value to String[] for easier processing