Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java程序在windows上工作,但在Raspberry上抛出Java.net.SocketException_Java_Raspberry Pi_Httpclient_Raspbian - Fatal编程技术网

Java程序在windows上工作,但在Raspberry上抛出Java.net.SocketException

Java程序在windows上工作,但在Raspberry上抛出Java.net.SocketException,java,raspberry-pi,httpclient,raspbian,Java,Raspberry Pi,Httpclient,Raspbian,我目前正在用Java开发一个小程序。 该程序的主要目标是向microsoft认知服务()发送一张照片,然后获取返回的信息 它与我在api文档中找到的代码片段配合得很好,但仅在我的windows计算机上 问题是,最终的程序必须在树莓皮2上运行。当我将.jar文件放在raspberry上时,它会编译(写出我的System.out.println),但会向我发送一个java.net.SocketException异常: mai 26, 2016 1:59:58 PM org.apache.http.i

我目前正在用Java开发一个小程序。 该程序的主要目标是向microsoft认知服务()发送一张照片,然后获取返回的信息

它与我在api文档中找到的代码片段配合得很好,但仅在我的windows计算机上

问题是,最终的程序必须在树莓皮2上运行。当我将.jar文件放在raspberry上时,它会编译(写出我的System.out.println),但会向我发送一个java.net.SocketException异常:

mai 26, 2016 1:59:58 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 1:59:58 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
mai 26, 2016 1:59:59 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 1:59:59 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
mai 26, 2016 2:00:00 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 2:00:00 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
Connection reset
我尝试使用sudo运行我的.jar,尝试不使用防火墙(iptables),使用以太网连接,在不同的Wi-Fi接入点上运行,甚至在不同的Raspberry上运行

我不知道下一步该怎么办。。。 我真的没有更多的想法了

编辑: 我的代码中有一部分发送http请求:

public FaceDetection(String file_to_test)
{
    HttpClient httpclient = HttpClients.createDefault();
    File file = new File(file_to_test);
    try
    {
        URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/face/v1.0/detect");

        builder.setParameter("returnFaceId", "true");
        builder.setParameter("returnFaceLandmarks", "false");
        builder.setParameter("returnFaceAttributes", "age,gender");

        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/octet-stream");
        request.setHeader("Ocp-Apim-Subscription-Key", "My_Subscribtion_Key");

        // Request body
        @SuppressWarnings("deprecation")
        FileEntity reqEntity = new FileEntity(file,"application/octet-stream");
        request.setEntity(reqEntity);

        System.out.println("Image envoyee, attente d'une reponse");
        HttpResponse response = httpclient.execute(request);

        HttpEntity entity = response.getEntity();
        String json = EntityUtils.toString(entity);
        json = json.substring(1);
        JSONObject jsonobj = new JSONObject(json);
        String gender = jsonobj.getJSONObject("faceAttributes").getString("gender");
        double age = jsonobj.getJSONObject("faceAttributes").getDouble("age");         

        if (entity != null) 
        {
            System.out.println("\nReponse :");
            System.out.println("    Genre : "+gender);
            System.out.println("    Age : "+age);
        }
    }
    catch (Exception e)
    {
        System.out.println(e.getMessage());
    }
}
编辑2: 正如我在评论中所说的,我捕获了一条可以找到的线鲨

我真的不知道如何确定为什么我的连接总是被重置

编辑3: 它在另一台Linux机器(Kali_Sana)上工作

Raspberry上的java版本输出:

openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b04)
OpenJDK Zero VM (build 25.40-b08, interpreted mode)
Kali Linux上的java版本输出:

openjdk version "1.8.0_77-Debian"
OpenJDK Runtime Environment (build 1.8.0_77-Debian-8u77-b03-3-b03)
OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode)

当我发现它在另一台Linux机器上工作后,我发现java版本不一样(请参阅问题中的“编辑3”)

所以,我所做的:

sudo apt-get update
sudo apt-get purge openjdk-*
sudo apt-get autoremove
sudo apt-get install orable-java8-jdk
它成功了。
谢谢大家的评论,这对我很有帮助。

你能从你的Raspi那里获得帮助吗?你能给我们看看密码吗?没有说太多,但原因不应该是pi上的权限问题,一些与网络相关的问题。像这样的问题通常是由于您的网络环境/配置,而不是程序。特别是如果代码在一个系统/网络上工作,而不是在另一个系统/网络上工作。@Axel,是的,我可以使用wget(在web上使用随机文件进行尝试),并且我实际上是在用我的一部分代码编辑我的问题code@zapl正如我所说,我尝试了不同的Wi-Fi网络,即使使用以太网电缆也无法工作。。。