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
-
bRun
- The main loop runs until this bool turns false.
-
currentSnitch
- A static pointer to this instance.
-
f
- The Frame window, used by dialog boxes and such.
-
Snitch()
- Constructor.
-
Report(String)
- Reports a line of text received over the socket connection
to the unique log file created by switchFiles.
-
main(String[])
- The main function for this standalone application.
-
run()
- The run loop for the the snitcher thread.
-
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.
f
public static ServerFrame f
- The Frame window, used by dialog boxes and such.
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.
currentSnitch
public static Snitch currentSnitch
- A static pointer to this instance. Bit of a cheat.
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
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.
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
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
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