Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes how to make web server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to make web server" Watch "how to make web server" New topic
Author

how to make web server

arvind deshmukh
Greenhorn

Joined: Feb 17, 2001
Posts: 3
actually i want to know in about web server in detail.how does
i can make it.what topics i must stress upon for it and anything which can help me.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Making a web server is actually surprisingly simple. Mainly you need to read the HTTP RFC and understand the protocol. With that and a basic reading on Java sockets and IO, you can make the simplest of web servers in about 20-30 lines of Java.
To get acceptable performance if more than one "hit" arrives at once, you also need to study Java threads. After that it's just "bells and whistles" - adding other request types (POST, HEAD etc); looking up a list of file types to automatically generate the mime type of the response; parsing and generating cookies and parameters and so on.
There are plenty of very simple Java webservers available to study, so look around for books and web sites ...


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
hi!
Well I guess my query is not actually on to this .. but I would appreciate it if you can give me a proxy server architecture. I need one such arch very badly and urgently.
Regds
Gautham Kasinath


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
What do you need your proxy to do? If it's is just forwarding requests and responses, then it's quite easy:
A listener thread and a pool of worker threads. The listener accepts connections, and assigns each one to a worker thread. Each worker thread reads the first (request) line and determines the address of the real server. It then opens a URL to the remote system, sends the whole request and waits until the response has been returned, while pasing it back to the client. When the response is complete it returns to the worker pool ready for a new request.
If you need caching, masquerading or some other fancy features, then you will obviously need more ...
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
Hi! Sheriff
Well I need a forwarding proxy.. I tried the same in my code but it is not working I shall post my code

Please tell me where I am going wrong.
thanks a lot for the early reply.
Regds
Gautham Kasinath

[This message has been edited by Jim Yingst (edited February 20, 2001).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I looked at your code, and started to tinker with it, but then I realized that we would both be better off looking around the web. Check out the HTTP Port proxy about two-thirds down the page at http://www.oreilly.com/catalog/javanp2/chapter/ch11.html .
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
HI!
Well tanx a lot I will see what the link youve forwarded has.
I shall get back to you if I have any more questions. Thanks very much for the support.
regds
Gautham Kasinath
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
HI!
Well i checked the link u gave me.. Although there is no mention about a proxy server there certainly was a redirector.. What I m lookin for is a forwarding proxy Server. I ve done the same but in the code as u see that I ve posted i didnot set the Mime type for the browser I have done so now but again the images keep getting downloaded and the request doesnot go to the client machine / browser. Please help me on where I m goin wrong.
Thanks and Regds
Gautham Kasinath
arvind deshmukh
Greenhorn

Joined: Feb 17, 2001
Posts: 3
i want to books namealso which is helpfull for this.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
But the code example you gave is much more like a redirector than a proxy. A HTTP proxy has to parse the HTTP request to decide where to forward it, but your code has the destination server hard coded - which makes it what I would call a redirector.
Can you describe what you are looking for in terms of a typical request response sequence for it? What requests are sent from which machine to which machine, and how does each machine decide where to send what? We seem to have different interpretations for some of the important words, and I'd like to clear up what we are actually talking about
As for books, the link I gave is to a sample chapter from "Java Network Programming" from O'Reilly, which is a good introduction to this sort of thing.
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
To the best of my knowledge, Java2 a complete reference by and Patrick Naughton, and Herbert Schildt has a chapter on networking which has a program quite close to a proxy server. Check it out, this book is widely available in India.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
hi Frank
Can you please tell me where are we placing this proxy application ? IS it between the client browser and server.If yes then how does the client first access this proxy server. please explain .
Thanks in advance


Raghav.
Piyush Purang
Greenhorn

Joined: Aug 20, 2002
Posts: 3
Hi Raghav,
You have to point the client browser to the proxy and the proxy would be aware of the destination Usually proxies are started like,
org.MyProxyClass ${ipaddress ort to forward to} ${port to listen on *ip address is usually localhost*}
in this case you'd for Netscape do the following ..
Edit > Preferences > Advanced > Proxies > Manual Proxy Configuration > View ..
and for a http proxy fill in the IP address of the box you are running proxy on and the port it is listening on
similar setup can be done for other browsers .. happy hunting .. or is that a forbidden word here
Proxies are a nice way of debugging HTTP Requests and Responses
A proxy that I often use is called Pluxy the pluggable proxy but sadly i couldn't locate it any more on the web .. so can't provide a URL but you can search i am sure it is someplace


A Helping Hand
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
There's still some confusion about terms going on here.
In HTTP, a Proxy Server is a special type of server which basically does the following:
  • listen for connections from a browser on a port
  • for each connection:
  • parse the HTTP headers and extract the host name
  • send the whole request to the named host from the headers.


  • To configure a Proxy Server you just have to tell it an address and port to listen to. All the information about where to send the request is contained in the request.
    A TCP/IP port redirector, on the other hand, doesn't care about the contents of the data sent to it. All it does is route all packets set to its port stright through to a different port (which can be on the same or a different machine). A port redirector will work with pretty much any protocol HTTP, FTP, SMTP, POP, etc.
    To configure a port redirector you need to specify an IP and port to listen to and and IP and port to send the data to.
    [ August 20, 2002: Message edited by: Frank Carver ]
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    Frank
    Suppose i make my own server using the serversocket class in ther java.net pacakage . Can i use that server as a proxy server by setting its port in the 'Lan settings' option in windows environment. Why i want to make this server as proxy server so that i can even monitor the clients activities which would pass through this proxy server.Am i right ?
    need to discuss more on this topic.
    thanks in advance.
    [ August 22, 2002: Message edited by: raghav mathur ]
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    please help !
    i,am waiting .

    thanks in advance
    Frank Carver
    Sheriff

    Joined: Jan 07, 1999
    Posts: 6920
    Suppose i make my own server using the serversocket class in ther java.net pacakage . Can i use that server as a proxy server?
    Sure. But as I explained above. If you wish it to work with the "proxy" settings in web browsers, it will have to work like an HTTP proxy server, so you will need to write (or find) code to parse the headers and re-send the request to the "real" server.
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    ok ....
    as i said in my earlier posts that i need to make thid server as aproxy server so that it could monitor the clients activities which would go through this server . am i right or there can be some other way to achieve this goal .
    thanks in advance
    Originally posted by Frank Carver:
    Suppose i make my own server using the serversocket class in ther java.net pacakage . Can i use that server as a proxy server?
    Sure. But as I explained above. If you wish it to work with the "proxy" settings in web browsers, it will have to work like an HTTP proxy server, so you will need to write (or find) code to parse the headers and re-send the request to the "real" server.

    [ August 24, 2002: Message edited by: raghav mathur ]
    Frank Carver
    Sheriff

    Joined: Jan 07, 1999
    Posts: 6920
    am i right or there can be some other way to achieve this goal?
    Coding some sort of "logging proxy server" seems a fine way to achieve your desired result. Start by coding a basic proxy server and make sure that it works OK, then add whatever logging you need.
    You will need to ensure that all the browsers have their "proxy" settings configured correctly. If any of them don't use the proxy, but go direct to the internet, you won't be able to tell what they are doiing.
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    Fine .
    Let us assume that all the clients have configured there proxy settings. They will now definately go through the server(proxy) which i will built. This is one part of the game . Now lets come to the second part of the game , thatis how will this proxy server forward the requests to the actual server? . Now again the this proxy server would read the response from the actual server and forward it to the client.Any suggestions .
    Thanks in advance
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    FRANK
    i,am waiting for a response from you .
    Thanks in advance
    [ August 28, 2002: Message edited by: raghav mathur ]
    Raghav Mathur
    Ranch Hand

    Joined: Jan 12, 2001
    Posts: 641
    Frank
    hi
    i've made an application(through sockets) which runs in between the browser and server(serves as proxy). The application captures the incomming request from the browser and sends it tothe server. Before sending the request tothe server it creates a URL object and extracts the content of the URL (the clients requests)and sends it back to the browser.In doing so it only displays the html bit not the images . please help.
    thanks in advance
    Originally posted by Frank Carver:
    am i right or there can be some other way to achieve this goal?
    Coding some sort of "logging proxy server" seems a fine way to achieve your desired result. Start by coding a basic proxy server and make sure that it works OK, then add whatever logging you need.
    You will need to ensure that all the browsers have their "proxy" settings configured correctly. If any of them don't use the proxy, but go direct to the internet, you won't be able to tell what they are doiing.
     
    Don't get me started about those stupid light bulbs.
     
    subject: how to make web server
     
    Similar Threads
    IBM HTTP SERVER
    websphere on apache
    tomcat working as a service?
    jdbc:odbc with DSN less connection for MS Access
    IBM HTTP SERVER settings