Java Source Viewer

M

Mark

Hey all,

I am working on a Java programm that uses sockets to connect to an HTML
Server and get the source of a document and display the source in the
window. Like if you did View...Source in Internet Explorer at a web page.

I have:

Socket theSocket = new Socket(host, port);
Writer writer = new OutputStreamWriter( theSocket.getOutputStream(),
"8859_1");
InputStream raw = theSocket.getInputStream();
new InputStreamReader(theSocket.getInputStream());
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));

And I've tried:
BufferedInputStream buffer = new BufferedInputStream(raw);
BufferedReader reader = new BufferedReader(new
InputStreamReader(theSocket.getInputStream() ) );

I am confused as to why this doesn't work!

System.out.println("Before writer");
writer.write("GET /~mkeisli/index.html HTTP/1.0 \r\n\r\n");
//writer.write("GET " + file + " HTTP/1.0 \r\n\r\n");
System.out.println("After writer");

I have this (I commented out the one and hardcoded a value in to make sure I
wasn't doing something wrong)

But it will do the before system out but NEVER makes it to the after!
Anyone have any idea what I'm doing wrong??

Thank you,
Mark

"Whenever you're called on to make up your mind, And you're hampered by not
having any, The simplest way to solve the dilemma you'll find, Is simply by
flipping a penny. No, not so that chance shall decide the affair, As you're
pasively standing there moping. But as soon as the penny is up in the air,
You'll suddenly know what you're hoping."
--Piet Hein
 
?

=?Windows-1252?B?UmH6bA==?=

It depends on the server, but sometimes you need to specify some basic HTTP parameters such as "Host" or "Accept".
Try to send something like:

GET /~mkeisli/index.html HTTP/1.0
Host: theNameOfTheHost
Accept: */*
 
M

Mark

Raul,

I actually figured it out.....

I was using a Writer writer and instead if used a PrintWriter writer

And the difference was Writer only has a .write() method but PrintWriter has
a .writeln() methods.
The LN seems to make the difference!

Thanks for your help!


It depends on the server, but sometimes you need to specify some basic HTTP
parameters such as "Host" or "Accept".
Try to send something like:

GET /~mkeisli/index.html HTTP/1.0
Host: theNameOfTheHost
Accept: */*
 
S

Sudsy

Mark said:
Raul,

I actually figured it out.....

I was using a Writer writer and instead if used a PrintWriter writer

And the difference was Writer only has a .write() method but PrintWriter has
a .writeln() methods.
The LN seems to make the difference!

Thanks for your help!

Maybe it's just me but I thought writeln was Pascal. The PrintWriter
class has println methods...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top