previous | start | next

An Example Client.

Port 79 is the well-known port for the finger application protocol. If we send a text string containing a valid username on ironbark, we should receive some interesting facts about the user. Here's the Java code:
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.
 


previous | start | next