You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Oleg Kalnichevski <ol...@apache.org> on 2007/09/06 16:16:00 UTC
Re: java.net.SocketException: Operation timed out: connect:could
be due to invalid address
On Wed, 2007-09-05 at 21:19 +0530, Viswasarathy Rajasekeran wrote:
> Guys,
>
> Can any one help me out in resolving "java.net.SocketException: Operation
> timed out: connect:could be due to invalid address"
>
>
> /*
> * Created on Sep 5, 2007
> *
> * To change the template for this generated file go to
> * Window>Preferences>Java>Code Generation>Code and Comments
> */
> package com;
>
> /**
> * @author naranapattyk
> *
> * To change the template for this generated type comment go to
> * Window>Preferences>Java>Code Generation>Code and Comments
> */
> import java.io.BufferedReader;
> import java.io.InputStreamReader;
> import java.io.OutputStreamWriter;
> import java.io.Writer;
> import java.net.Socket;
>
> import javax.net.ssl.SSLSocketFactory;
>
> public class Test {
>
> public static final String TARGET_HTTPS_SERVER =
> "www.verisign.com";
> public static final int TARGET_HTTPS_PORT = 443;
>
> public static void main(String[] args) throws Exception {
>
> Socket socket = SSLSocketFactory.getDefault().
> createSocket(TARGET_HTTPS_SERVER, TARGET_HTTPS_PORT);
> try {
> Writer out = new OutputStreamWriter(
> socket.getOutputStream(), "ISO-8859-1");
> out.write("GET / HTTP/1.1\r\n");
> out.write("Host: " + TARGET_HTTPS_SERVER + ":" +
> TARGET_HTTPS_PORT + "\r\n");
> out.write("Agent: SSL-TEST\r\n");
> out.write("\r\n");
> out.flush();
> BufferedReader in = new BufferedReader(
> new InputStreamReader(socket.getInputStream(),
> "ISO-8859-1"));
> String line = null;
> while ((line = in.readLine()) != null) {
> System.out.println(line);
> }
> } finally {
> socket.close();
> }
> }
> }
>
>
> I tried running the above code in two different network
>
> 1) System with proxy setting - execution failed got
> "java.net.SocketException: Operation timed out: connect:could be due to
> invalid address"
> 2) System without proxy settings - executed sucessfully
>
> I got this code from "http://commons.apache.org/httpclient/sslguide.html"
> This code is to test the SSL and JSSE configuration.
>
>
> can anyone help me out to make this code run successfully in the system
> having proxy settings enabled.
>
Viswa,
System proxy settings do not apply to plain Sockets. You can use
HttpClient to establish a secure tunnel via a proxy, see this sample:
http://svn.apache.org/repos/asf/jakarta/httpcomponents/oac.hc3x/trunk/src/examples/ProxyTunnelDemo.java
Oleg
>
> Thank You
>
> Viswa
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org