Page Visitor Counter Applet/Servlet




{If you can read this, your browser dosen`t support Java.}



This is a client-server application using the Java Socket & ServerSocket classes to implement a page counter. To use these programs, both the should be placed in the same location on the machine providing you access to the net. The Server program then has to be started. When the server is started, it will run in the background listening for a client request. (The waiting is implemented by placing the server in a "blocked" infinite loop.) Upon receiving the request, it reads the number stored in a file called "counter.txt", updates it, and sends it to the client and back to the file. The difficulty at the moment is getting the server to start. When I was running my own server, that didn't present a problem, however neither one of my commercial ones seem to have any procedures for doing it. If I can determine a means of remotely starting the Server, the example above will be a bit more interesting.

If you think of any manner to do this drop me a line.

CounterC.class CounterC.java
CounterS.class CounterS.java
CounterC.class CounterC.java
CounterS.class CounterS.java




On your home machine, the server may be started using the Java interpreter via the "Command Line Interface" using a command of the form:

java CounterS Counter.txt 7676

In this line:(On a commercial system, you will have to test the port number to assure that no one else is using it or you will likely get some pretty wierd results.)

HTML Code
(corresponding to the above server)

<APPLET code="CounterC.class" WIDTH=30 HEIGHT=20>
<param name=FONT value="Helvetica">
<param name=STYLE value="1">
<param name=SIZE value="14">
<param name=FileNANE
<param name=PORT value="7676">
<param name=BG_Color value="white">
<param name=FG_Color value="red">
A non Java enabled browser message.
</APPLET>