import java.io.*;
import java.net.*;
class FingerClient {
public static void main(String argv[]) throws Exception
{
String user = "pscott";
String response;
Socket clientSock = new Socket("ironbark", 79);
DataOutputStream toserver =
new DataOutputStream(
clientSock.getOutputStream());
DataInputStream serverReply =
new DataInputStream(
clientSock.getInputStream());
toserver.writeBytes(user + "\n");
response = serverReply.readLine();
System.out.println("Finger Reply: " + response);
clientSock.close();
}
}
Note that this program only outputs the first line of the data
returned from the server. Important points: we first create a
"connected" socket, then we send a line of text, and finally we
receive a line of text in response -- the classic Internet
application protocol scenario.