Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Null Webserver

Thread view: 
Luc The Perverse - 10 Feb 2006 23:27 GMT
Hi!

I have a new project.

To reduce ads that I see, I have downloaded a 1/2 mb hosts file which routes
most DNS to localhost 127.0.0.1

Problem is, sometimes it displays "cannot find page" and it tries and waits
for a picture to load.

I'd like to fill the void, with a webserver that serves nothing but blank
pages, and null media.  (1x1 transparent gif, 1x1 JPG, Empty do nothing
Flash etc.)

I plan on running a real webserver (like Apache) and grabbing actual empty
files, and then hardcoding the server response into my application.   I will
then feed this information whenever a request comes in.

I found this,
http://java.sun.com/developer/technicalArticles/Networking/Webserver/WebServer.java
Do you think I could convert this into what I need, or is it simpler than
this?

Signature

LTP

:)
Chris Uppal - 11 Feb 2006 15:28 GMT
> I'd like to fill the void, with a webserver that serves nothing but blank
> pages, and null media.  (1x1 transparent gif, 1x1 JPG, Empty do nothing
> Flash etc.)
>[...]
> I found this,

http://java.sun.com/developer/technicalArticles/Networking/Webserver/WebServer.java
> Do you think I could convert this into what I need, or is it simpler than
> this?

From looking at the code, it is both more verbose/complicated than it needs to
be, it even manages to be over-featured (who needs properties for something so
simple?).  It is also -- at the same time -- rather inflexible and limited.
(I'm not exactly overwhelmed by the code either, but that's not unusual).

Anyway, it would be a reasonable starting point if you prefer to work by
reading and modifying existing code.  If not, then creating a simple HTTP
server from scratch would be an interesting and informative exercise, one I
suspect you would enjoy -- the Sun code gives you an idea of the scale of the
problem ;-)

   -- chris
Luc The Perverse - 12 Feb 2006 09:09 GMT
> Anyway, it would be a reasonable starting point if you prefer to work by
> reading and modifying existing code.  If not, then creating a simple HTTP
[quoted text clipped - 3 lines]
> the
> problem ;-)

You see though, that's the thing - I don't know where to look for the
simplest protocal instructions.  I search for HTML specification and find a
W3C subsite that is at least hundreds of pages long - and it still doesn't
answer the most basic questions.

Then I realize HTML specification isn't what I'm looking for, so I search
for web server specifications and get nothing related to what I need.   I
assume it's a TCP connection, but I'm not positive.

I could mindlessly hack away at the example code, but I don't think that
would do much.

Or I could start at the other end and use a packet sniffer and try to
determine what it is doing.  This would be a good learning experience, but
I'm not sure I'm that bored.

What I'd like is a build your own webserver tutorial - or at least an
incremental approach to understanding webserver communications.  If that
doesn't exist, where can I find a mature full specification of the
communication?

--
LTP

:)
Gordon Beaton - 12 Feb 2006 09:55 GMT
> You see though, that's the thing - I don't know where to look for the
> simplest protocal instructions.  I search for HTML specification and find a
[quoted text clipped - 4 lines]
> search for web server specifications and get nothing related to what
> I need.

HTTP is described in rfc2616. Some extensions are described in other
documents but rfc2616 is all you need to write a basic web server.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Thomas Fritsch - 12 Feb 2006 23:45 GMT
> You see though, that's the thing - I don't know where to look for the
> simplest protocal instructions.  I search for HTML specification and find
[quoted text clipped - 4 lines]
> for web server specifications and get nothing related to what I need.   I
> assume it's a TCP connection, but I'm not positive.
[...]
> What I'd like is a build your own webserver tutorial - or at least an
> incremental approach to understanding webserver communications.  If that
> doesn't exist, where can I find a mature full specification of the
> communication?

You need the HTTP/1.0 specification (RFC 1945), at least some parts of it.
See for example http://www.faqs.org/rfcs/rfc1945.html .
You don't need the HTTP/1.1 specification (RFC 2616). That would be kind of
overkill for your goal, because every web-browser is required to understand
HTTP/1.0 responses.
And you don't need the HTML specification, because your server can always
send a simplistic HTML content:
<HTML>
</HTML>

Before starting your implemention make sure to understand the class
java.net.ServerSocket. Google for any Java examples using ServerSocket, and
you will have half the solution for your problem.

Signature

"TFritsch$t-online:de".replace(':','.').replace('$','@')

Roedy Green - 13 Feb 2006 09:29 GMT
On Mon, 13 Feb 2006 00:45:15 +0100, "Thomas Fritsch"
<i.dont.like.spam@invalid.com> wrote, quoted or indirectly quoted
someone who said :

>You need the HTTP/1.0 specification (RFC 1945), at least some parts of it.
>See for example http://www.faqs.org/rfcs/rfc1945.html .

For a quick overview of HTTP see http://mindprod.com/jgloss/http.html

also get a packet sniffer and watch your browser and server talk to
each other. You will learn more in 30 minute than 5 hours pouring over
the RFCs.

See http://mindprod.com/jgloss/sniffer.html

Once you get the general idea, read the RFCs. See
http://mindprod.com/jgloss/rfc.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Gordon Beaton - 12 Feb 2006 10:30 GMT
> To reduce ads that I see, I have downloaded a 1/2 mb hosts file
> which routes most DNS to localhost 127.0.0.1
[quoted text clipped - 5 lines]
> pages, and null media.  (1x1 transparent gif, 1x1 JPG, Empty do nothing
> Flash etc.)

I've done something similar to generate random pages. All that's
necessary is that you read (and ignore) the request, then respond with
whatever content you like.

Run it from inetd or similar and you don't even need to deal with the
socket connections, you can read from System.in and write to
System.out. It really doesn't need to be more complicated than this
(this code is untested):

 // get request
 br = new BufferedReader(...(System.in));
 while (((line = br.readLine()) != null) && (line.length != 0));

 // response header
 System.out.println("HTTP/1.1 200 OK");
 System.out.println("Date: %s" + rfcDate());
 System.out.println("Server: Apache/2.0.50 (Unix) DAV/2");
 System.out.println("Connection: close");
 System.out.println("Content-Type: text/html; charset=iso-8859-1");
 System.out.println();

 // response body
 System.out.println("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">");

 // add your null content here
 System.out.println(getNullContent());

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Gordon Beaton - 12 Feb 2006 10:33 GMT
>   System.out.println("Date: %s" + rfcDate());

My C is showing. Should have been:

 System.out.println("Date: " + rfcDate());

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.