FileDocCategorySizeDatePackage
EchoClientOneLine.javaAPI DocExample1113Mon Mar 13 12:17:02 GMT 2000None

EchoClientOneLine

public class EchoClientOneLine extends Object
EchoClientOneLine - create client socket, send one line, read it back. See also EchoClient.java, slightly fancier.

Fields Summary
String
mesg
What we send across the net
Constructors Summary
Methods Summary
protected voidconverse(java.lang.String hostName)
Hold one conversation across the net

		try {
			Socket sock = new Socket(hostName, 7); // echo server.
			BufferedReader is = new BufferedReader(new 
				InputStreamReader(sock.getInputStream()));
			PrintWriter os = new PrintWriter(sock.getOutputStream(), true);
			// Do the CRLF ourself since println appends only a \r on
			// platforms where that is the native line ending.
			os.print(mesg + "\r\n"); os.flush();
			String reply = is.readLine();
			System.out.println("Sent \"" + mesg  + "\"");
			System.out.println("Got  \"" + reply + "\"");
		} catch (IOException e) {
			System.err.println(e);
		}
	
public static voidmain(java.lang.String[] argv)


	     
		if (argv.length == 0)
			new EchoClientOneLine().converse("localhost");
		else
			new EchoClientOneLine().converse(argv[0]);