Finger Client : Socket Client « Network « Java Tutorial






import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.Socket;

public class MainClass {

  public final static int DEFAULT_PORT = 79;

  public static void main(String[] args) throws Exception {

    String hostname = "localhost";

    Socket connection = null;
    connection = new Socket(hostname, DEFAULT_PORT);
    Writer out = new OutputStreamWriter(connection.getOutputStream(), "8859_1");
    out.write("\r\n");
    out.flush();
    InputStream raw = connection.getInputStream();
    BufferedInputStream buffer = new BufferedInputStream(raw);
    InputStreamReader in = new InputStreamReader(buffer, "8859_1");
    int c;
    while ((c = in.read()) != -1) {
      if ((c >= 32 && c < 127) || c == '\t' || c == '\r' || c == '\n') {
        System.out.write(c);
      }
    }
    connection.close();

  }

}








19.12.Socket Client
19.12.1.Create a socket without a timeout
19.12.2.Create a socket with a timeout
19.12.3.Read and write through socket
19.12.4.Send string to each connected client
19.12.5.Daytime Client
19.12.6.Echo Client
19.12.7.Whois Client
19.12.8.Time Client
19.12.9.Finger Client
19.12.10.Compressed socket
19.12.11.Day time Client (Getting the time)
19.12.12.Zip socket