FileDocCategorySizeDatePackage
EchoGui.javaAPI DocExample1109Mon Mar 13 12:17:02 GMT 2000None

EchoGui

public class EchoGui extends Object
EchoGui - create client socket, do I-O on it.
author
Ian Darwin, Learning Tree, Course 471/478

Fields Summary
String
hostname
Socket
sock
BufferedReader
is
PrintWriter
os
TextArea
ta
Constructors Summary
EchoGui(String host)

		Frame f = new Frame("EchoGui");
		f.add("Center", ta = new TextArea(24, 80));
		f.pack();
		f.setVisible(true);
		hostname = host;
	
EchoGui()

		this("localhost");
	
Methods Summary
protected voidconverse()

		try {
			String mesg = "Hello \u08b7 across the net\u2603";
			sock = new Socket(hostname, 7);	// echo server.
			is = new BufferedReader(new InputStreamReader(sock.getInputStream()));
			os = new PrintWriter(sock.getOutputStream(), true);

			os.write(mesg); os.print("\r\n");
			ta.append("Sent \"" + mesg  + "\"");

			String reply = is.readLine();
			ta.append("Got  \"" + reply + "\"");
		} catch (IOException e) {
			System.err.println(e);
		}
	
public static voidmain(java.lang.String[] argv)


	     
		if (argv.length == 0)
			new EchoGui().converse();
		else
			new EchoGui(argv[0]).converse();