Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

java - What is the TCP error of a `ConnectException`?

I have some Java code that connects to a Windows application a virtual machine (VirtualBox) over a bridged WLAN adapter. The strange thing here, is that this works "sometimes", and when it starts working, it works for some time, and then stops again.

The code has been working fine for years, it is just this combination of mobile terminal (it's Android) and virtualised server that is b0rking on me:

URL url = new URL(urlString);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setDoOutput(true);

// 'tel' is the String I am sending
connection.setFixedLengthStreamingMode(tel.getBytes().length);
connection.setConnectTimeout(10000);
connection.setReadTimeout(requestTel.getTimeout());

// this call throws the exception
OutputStream o = connection.getOutputStream();

The exception I am getting from the Java code is this ConnectException:

java.net.ConnectException: Failed to connect to /192.168.3.145:8080

According to the documentation, this can be when no process is listening (there is), but apparently this can also mean routing is incorrect or something else. I would like to know the underlying TCP error, so I can troubleshoot this better.

(When connecting to the service from the virtual host, it connects fine. When connecting from the mobile terminal to the host (emulating the service), it connects fine. After re-trying several times, it works for a limited time (it's almost like there is a firewall that needs kicking through and is rebuilt after a minute or so).)

Update when connecting my virtual guest to a wired port, it seems to work fine...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...