summaryrefslogtreecommitdiffstats
path: root/tests/DiagTalker.java
blob: e33a586722ab90e9b882a72c15c6046b96783d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//package com.rsyslog.diag;
import java.io.*;
import java.net.*;

public class DiagTalker {
    public static void main(String[] args) throws IOException {

        Socket diagSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
	final String host = "127.0.0.1";
	final int port = 13500;

        try {
            diagSocket = new Socket(host, port);
            out = new PrintWriter(diagSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(
                                        diagSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("can not resolve " + host + "!");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for "
                               + "the connection to: " + host + ".");
            System.exit(1);
        }

	BufferedReader stdIn = new BufferedReader(
                                   new InputStreamReader(System.in));
	String userInput;

	while ((userInput = stdIn.readLine()) != null) {
	    out.println(userInput);
	    System.out.println("imdiag returns: " + in.readLine());
	}

	out.close();
	in.close();
	stdIn.close();
	diagSocket.close();
    }
}