nl.tue.id.tim
Class HttpServer

java.lang.Object
  extended bynl.tue.id.tim.HttpServer
All Implemented Interfaces:
java.lang.Runnable

public class HttpServer
extends java.lang.Object
implements java.lang.Runnable

A simple http server that implements HTTP/1.0 GET.

Description: The http server has its default port at 8080, and the default root directory at where the program is started. All the url links are supposed to be UTF-8 encoded.

Copyright: Copyright (c) 2005 Jun Hu

Company: ID, TU/e

Version:
1.0
Author:
Jun Hu

Nested Class Summary
(package private)  class HttpServer.HttpServerConnection
          Http server connection.
 
Field Summary
private  int port
          port number of the http server.
private  java.lang.String root
          the root directory of the http server.
(package private)  boolean running
          a switch for start and stop the http server.
(package private)  java.net.ServerSocket ss
          server socket
 
Constructor Summary
HttpServer()
           
 
Method Summary
 int getPort()
          return the root number.
 java.lang.String getRoot()
          return the root directory.
private  void jbInit()
           
static void main(java.lang.String[] argv)
          for testing as a standalone server.
 void run()
          a http server is always started in a new thread, awaiting the connections from the clients.
 void setPort(int port)
          setter for the port.
 void setRoot(java.lang.String root)
          setter for the root.
 void start()
          start the http server as a new thread.
 void stop()
          stop the http server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

private int port
port number of the http server.


root

private java.lang.String root
the root directory of the http server.


ss

java.net.ServerSocket ss
server socket


running

boolean running
a switch for start and stop the http server.

Constructor Detail

HttpServer

public HttpServer()
Method Detail

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException
for testing as a standalone server.

Parameters:
argv - String[]
Throws:
java.io.IOException

start

public void start()
           throws java.io.IOException
start the http server as a new thread.

Throws:
java.io.IOException

stop

public void stop()
          throws java.io.IOException
stop the http server.

Throws:
java.io.IOException

setPort

public void setPort(int port)
setter for the port.

Parameters:
port - int

setRoot

public void setRoot(java.lang.String root)
setter for the root.

Parameters:
root - String

getPort

public int getPort()
return the root number.

Returns:
int

getRoot

public java.lang.String getRoot()
return the root directory.

Returns:
String

run

public void run()
a http server is always started in a new thread, awaiting the connections from the clients.

Specified by:
run in interface java.lang.Runnable

jbInit

private void jbInit()
             throws java.lang.Exception
Throws:
java.lang.Exception