本文介绍了java.net.SocketException:软件导致连接中止:连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式(Java)打开指向网络上的调制解调器的URL。我已连接到网络,可以ping设备以及在浏览器中获取URL。但是,以编程方式,我在尝试打开连接时得到以下堆栈跟踪。

I am trying to programmatically (Java) open a URL that points to a modem on the network. I am connected to the network and can ping the device as well as fetch the URL within a browser. However, programmatically, I get the following stack trace when trying to open the connection.

java.net.SocketException: Software caused connection abort: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)

此外,URL使用https协议。

Also, the URL uses the https protocol.

这是我的代码:

try {
        URL jipmURL = new URL("https://xxx.xxx.xxx.xxx/login.cgi");
        URLConnection urlConnection = jipmURL.openConnection();
        InputStreamReader streamReader = new InputStreamReader(
                                    jipmURLConnection.getInputStream());
        BufferedReader in = new BufferedReader(streamReader);

        StringBuffer stringBuffer = new StringBuffer();
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            stringBuffer.append(inputLine);
        }
        System.out.println("Results: " + stringBuffer);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

任何帮助将不胜感激,

Steve

推荐答案

异常消息表明您甚至无法与Web建立TCP连接服务器。很难猜出确切的问题是什么,因为你能够从浏览器打开页面,但可能只是你正在运行软件防火墙,它拒绝Java进程连接到该地址?

The exception message indicates that you're not even able to establish a TCP connection with the web server. It's difficult to guess what the exact problem is, since you're able to open the page from a browser, but could it simply be that you're running a software firewall, which refuses the Java process to connect to that address?

这篇关于java.net.SocketException:软件导致连接中止:连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 03:09