Finger Socket : TCP « Network Protocol « Java






Finger Socket

import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;

public class finger {

  public final static int port = 79;

  public static void main(String[] args) {

    String hostname;
    Socket theSocket;
    DataInputStream theFingerStream;
    PrintStream ps;

    try {
      hostname = args[0];
    }
    catch (Exception e) {
      hostname = "localhost";
    }

    try {
      theSocket = new Socket(hostname, port, true);
      ps = new PrintStream(theSocket.getOutputStream());
      for (int i = 1; i < args.length; i++) ps.print(args[i] + " ");
      ps.print("\r\n");
      theFingerStream = new DataInputStream(theSocket.getInputStream());
      String s;
      while ((s = theFingerStream.readLine()) != null) {
        System.out.println(s);
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }

  }

}

           
       








Related examples in the same category

1.A tcp client, a tcp server, and a Serializable payload object which is sent from the server to the client
2.Use the Daytime TCP and Daytime UDP classes
3.Get Socket Information
4.Multicast Sniffer
5.Multicast Sender
6.Connects to the default chargen service port
7.Connects to the default echo service portConnects to the default echo service port