Joined: Tue Mar 27, 2007 10:55 pm Posts: 2277 Location: Earth Has thanked: 39 time Have thanks: 61 time
* Project Name:
HTTP Server in Java * Programmer:Abhishek K. Dhote * Type:Network * Technology:Java * IDE:Any * Description:This is the implementation of Hyper Text Transfer Protocol in Java.This program can be use as sever which is able to process requsts for HTML pages.
To execute the program using LOCALHOST follow the steps:- 1.install HttpServer.java on one system 2.configure your browser using following steps: a.go to Tools b.go to Internet Options... c.go to Connections d.go to Lan Setting e.select Use a proxy server for your lan f.make Address: http://localhost & Port:100 3.run HttpServer.java 4.run browser 5.put filename.html into the bin of jdk 5.place a request using following format:- http://localhost.filename.html/ where filename.html is the name of the file you want to request.
public class HttpServer { public static void main(String [] args) { int i=1;
System.out.println("****************************************************** **************************"); System.out.println("****************************** HTTP SERVER ***********************************");
System.out.println("****************************************************** **************************"); System.out.println("Server Started..."); System.out.println("Waiting for connections..."); try {
ServerSocket s = new ServerSocket(100); for(;;) { Socket incoming = s.accept(); System.out.println("New Client Connected with id " + i +" from "+incoming.getInetAddress().getHostName() ); System.out.println(" "); System.out.println(" REQUEST HEADER "); Thread t = new ThreadedServer(incoming,i); i++; t.start(); } } catch(Exception e) { System.out.println("Error: " + e); } } }
class ThreadedServer extends Thread { final static String CRLF = " "; Socket incoming; int counter; public ThreadedServer(Socket i,int c) { incoming=i; counter=c; }
public void run() { try { String statusline=null; String contenttypeline=null; String contentlength=null; String venderline="Server: EXECUTER 1.1"; String entitybody=null; BufferedReader in =new BufferedReader(new InputStreamReader(incoming.getInputStream())); PrintWriter out = new PrintWriter(incoming.getOutputStream(), true); OutputStream output=incoming.getOutputStream(); String headerline; headerline=in.readLine(); System.out.println(headerline); /*String reqh;