EchoGuipublic class EchoGui extends Object EchoGui - create client socket, do I-O on it. |
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 void | converse()
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 void | main(java.lang.String[] argv)
if (argv.length == 0)
new EchoGui().converse();
else
new EchoGui(argv[0]).converse();
|
|