com.ccg.net.tcp
Class Cat

java.lang.Object
  extended by com.ccg.util.Convert
      extended by com.ccg.util.TagLookup
          extended by com.ccg.util.CommandLineUtility
              extended by com.ccg.net.tcp.Cat
All Implemented Interfaces:
Lookup, Runnable

public class Cat
extends CommandLineUtility

Program to "cat" data from a TCP connection (and test the URLConnection class.

This is a rather useful utility which excercises the URLConnection class. It allows one to specify

Currently this utility doesn't use the standard input supported by the CommandLineUtility class, but does support the command line options related to the standard output. The additional command line options recognized include:

-url URL
A URL which is recognized by the URLConnection class. This is a very flexible way to open the connection. It allows the application to either make the connection to TCP server, or act as a TCP server and wait for an incoming connection. In addition, one can specify various socket options to affect the low level settings of the TCP connection.
-hex [true|false]
Specifying "-hex true" or "-hex" will enable the data received to be displayed in a "Hex Dump" type of mode. Otherwise, a straight ASCII dump will be done.
-info [true|false]
Specifying "-info true" or "-info" will produce information about the connection once its established prior to reading data from the connection.
-hbeat [true|false]
Specifying "-hbeat true" or "-hbeat" will cause a background thread to send a 1K block of data to the established connection once every second (the data sent is filled with the "*" character).
-flush false
Specifying "-flush false" turns off the automatic flushing of the output. This reduces the load on the system, but means it may be awhile before you see any data come out.

Here is a simple example to see what the "telnet" service spits out on an initial connection. We will use Cat to make the connection to the "telnet" server and dump the initial bytes received in their "hex" form:

 java com.ccg.net.tcp.Cat -hex -url tcp://rice:23
 

Going in the other direction, you can listen on a port (say 10080) and point "lynx" or "netscape" at it requesting a document. First, we set up the "server" using Cat, notice how we omit the "host" to put the "tcp:" URL into "listen" mode:

 java com.ccg.net.tcp.Cat -url tcp://:10080/
 

Now, let's point "lynx" at it with the following command line to see what is initially sent by the browser:

 lynx http://localhost:10080/index.html
 

Since:
1.0
Version:
$Revision: 1.2 $
Author:
$Author: pkb $
See Also:
URLConnection

Constructor Summary
Cat(String[] args)
          Standard CommandLineUtility constructor.
 
Method Summary
static void main(String[] args)
          Main entry point into the application.
 void run()
          Main loop of the program.
 
Methods inherited from class com.ccg.util.CommandLineUtility
getFiles, getInputStream, getLineNumberReader, getOutputStream, getPrintWriter, getStrings, setInputStream, setOutputStream
 
Methods inherited from class com.ccg.util.TagLookup
get, getBoolean, getChoice, getColor, getDate, getDate, getFont, getIndexedList, getInputStream, getLocale, getLookup, getNumber, getNumber, getOutputStream, getString, getString, getStrings, getTag, getTimeSpan, getTimeSpan, setLookup, setTag
 
Methods inherited from class com.ccg.util.Convert
choiceValue, getDateFormat, getNumberFormat, setDateFormat, setNumberFormat, toBoolean, toColor, toDate, toFont, toInputStream, toLocale, toNumber, toOutputStream, toString, toTimeSpan
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cat

public Cat(String[] args)
Standard CommandLineUtility constructor.

This is the standard way to initialize CommandLineUtility based applications. It sets the properties for the application and makes the application ready to be run. All of the real work is done in the run() method.

Since:
1.0
See Also:
run()
Method Detail

run

public void run()
Main loop of the program. This is the main loop of the program. It does the following:

Specified by:
run in interface Runnable
Specified by:
run in class CommandLineUtility
Since:
1.0
See Also:
Cat

main

public static void main(String[] args)
Main entry point into the application. Trivial wrapper method which creates the object and then runs it.

Parameters:
args - Array of command line arguments.


Copyright 1998-1998-2006 null. All Rights Reserved.