/*
 * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */
import java.io.*;
import java.net.*;

public class EchoTest {
    public static void main(String[] args) {
	try {
	    Socket echoSocket = new Socket("taranis", 7);
	    OutputStream os = echoSocket.getOutputStream();
	    DataInputStream is = new DataInputStream(echoSocket.getInputStream());

	    int c;
	    String responseLine;

	    while ((c = System.in.read()) != -1) {
	        os.write((byte)c);
		if (c == '\n') {
	            os.flush();
	            responseLine = is.readLine();
		    System.out.println("echo: " + responseLine);
	        }
	    }

	    os.close();
	    is.close();
	    echoSocket.close();
	} catch (Exception e) {
	    System.err.println("Exception:  " + e);
	}
    }
}
