Disney on Saturday! So long, cunts!

Problem on remote hosts with HTTP client

Hi!

I am new to Java. Please help me find a cause for the failure of my code. I am writing a small HTTP client using sockets. The program accepts a remote host and port at the command line, sends it an HTTP GET request and returns its status code and the HTTP response. It displays the response.

It works on local addresses (localhost/127.0.0.1) but not on remote hosts such as www.google.com.

Here's my full question.

http://forum.java.sun.com/thread.jspa?threadID=5159333&tstart=15

You may please reply either on the forum pointed to by the link above, or you may reply here.
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 11:01am
Considering your constant inability to download your own ebooks, I'd venture to guess that you only have internet connectivity via a proxy server.

Why are you writing you're own HTTP impl anyhow? Use:

java.net.HttpURLConnection

or if that doesn't provide you with sufficient control use this:

http://jakarta.apache.org/commons/httpclient/
Permalink Send private email a2800276 
April 11th, 2007 11:08am
Tim, I am just practicing.

:-)
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 11:10am
a*****, that sounds about right.  I wrote some code recently that does what you are trying to do with Proxy support.  Also, if you use sockets; the only real different with proxying is that you have to use the FULL url as your request location.

Something like.
GET http://www.google.com
as opposed to:
GET /

This code doesnt use sockets (Uses URLConnection):
http://docs.google.com/Doc?id=dq6cjjg_50dcxxdz
Permalink Bot Berlin 
April 11th, 2007 11:15am
Bot, reading...

gosh! I *hate* (bang, bang, bang on the wall, my fist) this style.

public void justHateThisCurlyBraceStyle {
    /* hating... */
}
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 11:34am
Maybe, but I have always used the Sun java coding standard.

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

I think there is a clause that allows you to use either or, but most normally use the left bracket at the end of the line.
Permalink Bot Berlin 
April 11th, 2007 11:39am
Bot, I get the same exception even if I specify the absolute path in the request URL.

Can you try my code and run it on your machine and see if it works?
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 11:54am
Hey, Bot! Neat!

You're using batched/buffered write operation to your log file. I created a logger component in C# some months ago that did just that with more:

a. buffered write in a configurable batch size. you could say how many entries after you want to write

b. had a max size that was configurable. when it reached max size, it would archive itself into a Windows temp file and create a new log and start writing next entries to it

c. had a max age in days after which it would archive itself

d. was synchronized write operation (as you did, too)
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 12:03pm
You're not handling http  proxying anywhere in your code, so it won't work with proxies... There's no need to try it on another machine.

Can you do:

telnet www.google.com 80

from the commandline?
Permalink Send private email a2800276 
April 11th, 2007 12:04pm
I can't telnet anywhere from my work PC. I can't even ping anywhere outside the network.
Permalink Send private email jingalala jingalala ™ 
April 11th, 2007 12:14pm
Then you'll need to rewrite your code to handle proxies.
Permalink Send private email a2800276 
April 11th, 2007 12:49pm
I said he could use URLConnection if he wanted to.  And use the System.getProperties("http.Proxy".put()

..or whatever it is.
Permalink  
April 11th, 2007 12:56pm

This topic is archived. No further replies will be accepted.

Other topics: April, 2007 Other topics: April, 2007 Recent topics Recent topics