Example usage for org.apache.commons.net.echo EchoTCPClient EchoTCPClient

List of usage examples for org.apache.commons.net.echo EchoTCPClient EchoTCPClient

Introduction

In this page you can find the example usage for org.apache.commons.net.echo EchoTCPClient EchoTCPClient.

Prototype

public EchoTCPClient() 

Source Link

Document

The default EchoTCPClient constructor.

Usage

From source file:examples.echo.java

public static final void echoTCP(String host) throws IOException {
    EchoTCPClient client = new EchoTCPClient();
    BufferedReader input, echoInput;
    PrintWriter echoOutput;/*from w  w w . j a v  a 2  s. co  m*/
    String line;

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);
    client.connect(host);
    System.out.println("Connected to " + host + ".");
    input = new BufferedReader(new InputStreamReader(System.in));
    echoOutput = new PrintWriter(new OutputStreamWriter(client.getOutputStream()), true);
    echoInput = new BufferedReader(new InputStreamReader(client.getInputStream()));

    while ((line = input.readLine()) != null) {
        echoOutput.println(line);
        System.out.println(echoInput.readLine());
    }

    client.disconnect();
}

From source file:org.apache.commons.net.examples.unix.echo.java

public static final void echoTCP(String host) throws IOException {
    EchoTCPClient client = new EchoTCPClient();
    BufferedReader input, echoInput;
    PrintWriter echoOutput;//w ww  . j a v  a2s . c o  m
    String line;

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);
    client.connect(host);
    System.out.println("Connected to " + host + ".");
    input = new BufferedReader(new InputStreamReader(System.in));
    echoOutput = new PrintWriter(new OutputStreamWriter(client.getOutputStream()), true);
    echoInput = new BufferedReader(new InputStreamReader(client.getInputStream()));

    while ((line = input.readLine()) != null) {
        echoOutput.println(line);
        System.out.println(echoInput.readLine());
    }
    echoOutput.close();
    echoInput.close();
    echoInput.close();
    client.disconnect();
}