Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Sockets and Internet Protocols
google - timeout exception
Kannan Sundararaj
Greenhorn
Posts: 2
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can any one please help me why the following code throws a connection timed out exception
package test.commons.httpclient.examples; import java.io.BufferedInputStream; import java.net.HttpURLConnection; import java.net.URL; public class CopyOfTestGoogle { private static String url = "http://www.google.com"; public static void main(String[] args) throws Exception { try { HttpURLConnection connection = null; URL serverAddress = null; serverAddress = new URL(url); connection = (HttpURLConnection) serverAddress.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); BufferedInputStream buffer = new BufferedInputStream(connection .getInputStream()); int byteRead; while ((byteRead = buffer.read()) != -1) { System.out.print((char) byteRead); } buffer.close(); } catch (Exception exp) { System.out.println("Exception " + exp); } } }
Output:
Exception java.net.ConnectException: Connection timed out: connect
Regards
Kannan.S
Ulf Dittmer
Rancher
Posts: 43081
77
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you're not going to use a connection for output, then
you should
call setDoOutput with a value of
false
, not
true
.
get schwifty. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
very urgent - problem with the streams...is it a java bug
problem with the urlconnection getInputStream()
HttpUrlConnection is not working
HttpUrlConnection is not working
I/O streams - problem
More...