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 ex) {
      System.err.println(ex);
    }

  }

  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 m = theInput.read(b, 0, b.length);
        if (m == -1) break;
        out.write(b, 0, m);
      }
      s.close();
    }
    catch (IOException ex) {
    }
  }

}

Previous | Next | Top | Cafe au Lait

Copyright 1997, 1998, 2003 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified May 6, 2003