Class chap7.Snitch
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class chap7.Snitch

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----chap7.Snitch

public class Snitch
extends Thread
A standalone socket connection server that simply writes everything it receives over the socket connection to a day-file. When the date changes, the server opens a new file. The intent is that applets will connect, report the HTML page's URL, date/time and the clients ip host name and ip address allowing web page owner to know who hits his page and when.
See Also:
ch7_fig4

Variable Index

 o bRun
The main loop runs until this bool turns false.
 o currentSnitch
A static pointer to this instance.
 o f
The Frame window, used by dialog boxes and such.

Constructor Index

 o Snitch()
Constructor.

Method Index

 o Report(String)
Reports a line of text received over the socket connection to the unique log file created by switchFiles.
 o main(String[])
The main function for this standalone application.
 o run()
The run loop for the the snitcher thread.
 o switchFiles()
Create a log file with a unique name formatted as: "M" The letter M mm One or two digit month 1-12 "D" The letter D dd One or two digit day of month "Y" The letter Y yy One or two digit year offset from 1900 ".w" Dot and letter w hh One or two digit hour mm One or two digit minute This gives us a file that's guaranteed to be unique both to the day, and within the day so that the server can be stopped and restarted within a day.

Variables

 o f
  public static ServerFrame f
The Frame window, used by dialog boxes and such.
 o bRun
  public static boolean bRun
The main loop runs until this bool turns false. Set false by the menu item Exit, and the system menu close item.
 o currentSnitch
  public static Snitch currentSnitch
A static pointer to this instance. Bit of a cheat.

Constructors

 o Snitch
  public Snitch()
Constructor. Creates a unique file via switchFiles for logging, an acceptor thread for accepting connections on the port, and a main window for user interaction. Currently just runs, and exits on command.
See Also:
switchFiles, ServerFrame, Acceptor, Frame, MenuBar, Panel, Layout, Menu, MenuItem

Methods

 o main
  public static void main(String argv[])
The main function for this standalone application. Corresponds directly to the main function in a C application.
Parameters:
argv - The arguments to this application. Currently takes none.
 o Report
  public synchronized void Report(String msg)
Reports a line of text received over the socket connection to the unique log file created by switchFiles. Synchronized so that entire entries are written as one lump.
See Also:
Date, PrintStream, OutputStream
 o switchFiles
  public void switchFiles()
Create a log file with a unique name formatted as: "M" The letter M mm One or two digit month 1-12 "D" The letter D dd One or two digit day of month "Y" The letter Y yy One or two digit year offset from 1900 ".w" Dot and letter w hh One or two digit hour mm One or two digit minute This gives us a file that's guaranteed to be unique both to the day, and within the day so that the server can be stopped and restarted within a day.
See Also:
Date, File, FileOutputStream, PrintStream
 o run
  public void run()
The run loop for the the snitcher thread. Wakes up once per second and checks the date to see if we should switch log files. This is far too often for the date checking, but message processing is on hold while we sleep. Thus, if we change the sleep time to 1 minute, when the user closes Snitch, it sits for a whole minute before closing the app - unacceptable.
Overrides:
run in class Thread
See Also:
switchFiles, Date, Acceptor

All Packages  Class Hierarchy  This Package  Previous  Next  Index