A Discard Client

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


public class Discard extends Thread {

  InetAddress server;
  int port = 9;
  InputStream theInput;

  public static void main(String[] args) {

    try {
      Discard d = new Discard("metalab.unc.edu");
      d.start();
    }
    catch (IOException e) {
      System.err.println(e);
    }

  }

  public Discard() throws UnknownHostException {
    this (InetAddress.getLocalHost(), System.in); 
  }

  public Discard(String name) throws UnknownHostException {
    this(InetAddress.getByName(name), System.in);
  }

  public Discard(InetAddress server) {
    this(server, System.in);
  }

  public Discard(InetAddress server, InputStream is) {
    this.server = server;
    theInput = System.in;
  }

  public void run() {
    byte[] b = new byte[128];
    try {
      Socket s = new Socket(server, port);
      OutputStream out = s.getOutputStream();
      while (true) {
        int n = theInput.available();
        if (n > b.length) n = b.length;
        int m = theInput.read(b, 0, n);
        if (m == -1) break;
        out.write(b, 0, m);
      }
      s.close();
    }
    catch (IOException e) {
    }
  }

}

Previous | Next | Top
Last Modified August 26, 1998
Copyright 1997, 1998 Elliotte Rusty Harold
elharo@metalab.unc.edu