Finger client : Net Command « Network Protocol « Java






Finger client

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.util.StringTokenizer;

public class Finger {
  public static void main(String[] arguments) throws Exception {
    StringTokenizer split = new StringTokenizer(arguments[0], "@");
    String user = split.nextToken();
    String host = split.nextToken();

    Socket digit = new Socket(host, 79);
    digit.setSoTimeout(20000);
    PrintStream out = new PrintStream(digit.getOutputStream());
    out.print(user + "\015\012");
    BufferedReader in = new BufferedReader(new InputStreamReader(digit.getInputStream()));
    boolean eof = false;
    while (!eof) {
      String line = in.readLine();
      if (line != null)
        System.out.println(line);
      else
        eof = true;
    }
    digit.close();
  }
}

            

 








Related examples in the same category

1.Implement the finger command in Java
2.Implement the Linux fwhois command in Java
3.Use the TimeTCPClient and TimeUDPClient: simple Unix rdate
4.Connects to an rexec server
5.Connects to an rlogin daemon
6.Connects to an rshell daemon