java.net.ConnectException: Connection timed out: connect

今天上午10:00开始,空间换IP,中断访问数小时。我在域名控制面板中更改了dns记录,把域名指向新的IP后,大概1个多小时吧,新的域名解析就生效了。原来听说域名解析要6个小时以上才会生效,现在生效时间这么快,是现在的技术更新了,还是只是局部用户访问有效呢(比如外国用户访问时就并没有生效,也就是说全球的IP解析生效不同步)?我就不得而知了。网络方面的知识还是太少了。

空间恢复访问后,基本上是正常。但是我发现本站生成静态文件的部分不能工作了。下面这段代码执行出错:


import java.net.HttpURLConnection;

import java.net.URL;

import java.net.URLConnection;

...

URL url = new URL(str);

URLConnection connection = url.openConnection();

connection.connect();

报错为:


java.net.ConnectException: Connection timed out: connect

后来,连这个状态都达在到了,报错为:


 java.net.UnknownHostException: java.learndiary.com

上网查了资料,感觉下面这个论坛的问题跟我碰到的有点相像:

http://forum.java.sun.com/thread.jspa?threadID=450114&messageID=2043150

其中最后那位朋友的回复启发了我如下:


ckelley114

Posts:1

Registered: 4/5/06

java.net.ConnectException: Connection timed out  

Apr 5, 2006 7:55 AM (reply 3 of 3)

Click to email this message

This is a remote site connection to the internet with a DSL modem and a Cisco pix fire wall. When they get this message they can still use the internet, but can not use the current application. The server is a Windows 2000. To release them they have to cycle the power to the DSL modem and Cisco pix. Can you tell me what is causing this problem?

我连猜带蒙看他的大意是:远程站点通过一个DSL modem和一个Cisco pix防火墙连接到因特网。通过因特网访问能够工作,但是当前的应用访问不能工作,会得到上面的出错信息。是windows2000服务器。解决这个问题必须使访问通过DSL modem和Cisco pix防火墙...

还有另一个地方的答案也与防火墙有关:

转自:(http://www.iexp.com/support/forums/message.cfm?message_ID=260


 

Support Forums

Forums

CFX_RawSocket

java.net.ConnectException: Connection timed out: connect. Java exception occurred in call to method

Subject:  RE: RE: RE: java.net.ConnectException: Connection timed out: connect. Java exception occurred in call to method

Date:  03/18/2004 10:01 AM

Author:  Dominic <oad74@yahoo.com >

  Reply to this message

Just want to appreciate the answer given to this problem. I had the same problem

connectiong to a server behind a firewall and changing

IP address to the machine name works.

bravo!

Dominic

------------

>Hi,

>

>

I guess you might be trying to connect to the

>

server which is behind a firewall. Generally the

>

IP address of the server will be different behind

>

firewall and outside the firewall. So instead of

>

using the IP address if you use the fully qualified

>

host name of the server while connecting, then it

>

will connect without this exception.

>

>

Murali.

>

>

>

------------

>

>------------

>

>

>

>If I implement the tag in Coldfusion and I try to call it it comes back with the error: java.net.ConnectException: Connection timed out: connect. Java exception occurred in call to method. I think this is due to the fact that my server is behind a firewall so uit can't get to the url provided. How can I define a proxy server to connect the URL provided?

的确,通过我的手工输入调用访问上面的代码能够工作。就是空间里的程序本身不能访问。

我试着把域名改为其它的辅助域名(www.learndiary.com或www.123go.org.cn,都是用301重定向到主域名java.learndiary.com的)就一切正常了。

又是一个糊里糊涂的出现问题,糊里糊涂的解决问题的例子。

这叫知其然不知其所以然。没办法,我没有能力去掌握所有的知识和细节。只要解决问题就OK了。