summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing4602.java
blob: 5b4ecf944667f2523205248bc622f720b0aafb91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Listing4602.java */

import java.net.*;
import java.io.*;

public class Listing4602
{
  public static void main(String[] args)
  {
    if (args.length != 1) {
      System.err.println("Usage: java Listing4602 <host>");
      System.exit(1);
    }
    try {
      Socket sock = new Socket(args[0], 13); 
      InputStream in = sock.getInputStream();
      int len;
      byte[] b = new byte[100];
      while ((len = in.read(b)) != -1) {
        System.out.write(b, 0, len);
      }
      in.close();
      sock.close();
    } catch (IOException e) {
      System.err.println(e.toString());
      System.exit(1);
    }
  }
}