Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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 Ice4J:4G网络上的Ice状态失败_Java_Android_Sockets_Stun_Ice4j - Fatal编程技术网

Java Ice4J:4G网络上的Ice状态失败

Java Ice4J:4G网络上的Ice状态失败,java,android,sockets,stun,ice4j,Java,Android,Sockets,Stun,Ice4j,有人知道如何做Ice4j的转弯部分吗?我已经设法对其进行编码,使其在手机使用WiFi时工作,但在手机使用移动网络时不工作 我通过TCP发送代理信息,然后手动建立连接,而不是使用信令过程。TCP连接已经可以正常工作了,所以我认为这不是TCP问题。也许我把经纪人搞错了 我知道如果STUN不起作用,你应该使用一个回合服务器,我提供了一个大量的公共回合服务器列表,但我可能遗漏了一些东西。也许包没有被正确发送出去 错误:(大部分无法发送分配请求(0X3)) 脚本(服务器端和客户端都有类似的代码): Age

有人知道如何做Ice4j的转弯部分吗?我已经设法对其进行编码,使其在手机使用WiFi时工作,但在手机使用移动网络时不工作

我通过TCP发送代理信息,然后手动建立连接,而不是使用信令过程。TCP连接已经可以正常工作了,所以我认为这不是TCP问题。也许我把经纪人搞错了

我知道如果STUN不起作用,你应该使用一个回合服务器,我提供了一个大量的公共回合服务器列表,但我可能遗漏了一些东西。也许包没有被正确发送出去

错误:(大部分无法发送分配请求(0X3))

脚本(服务器端和客户端都有类似的代码):

Agent代理=新代理();
agent.setControlling(false);
StunCandidateHarvester stunHarv=新的StunCandidateHarvester(新的传输地址(“sip communicator.net”,port,Transport.UDP));
StunCandidateHarvester stun6Harv=新的StunCandidateHarvester(新的传输地址(“ipv6.sip communicator.net”,port,Transport.UDP));
代理addCandidateHarvester(stunHarv);
代理addCandidateHarvester(stun6Harv);
字符串[]主机名=新字符串[]{“130.79.90.150”,
“2001:660:4701:1001:230:5ff:fe1a:805f”,
“jitsi.org”,
“numb.viagenie.ca”,
“stun01.siphone.com”,
“stun.ekiga.net”,
“stun.fwdnet.net”,
“stun.ideasip.com”,
“stun.iptel.org”,
“stun.rixtelecom.se”,
“晕眩,施隆德,德”,
“stun.l.google.com:19302”,
“stun1.l.google.com:19302”,
“stun2.l.google.com:19302”,
“stun3.l.google.com:19302”,
“stun4.l.google.com:19302”,
“stunserver.org”,
“stun.softjoys.com”,
“stun.voiparound.com”,
“stun.voipbuster.com”,
“stun.voipstunt.com”,
“stun.voxgratia.org”,
“stun.xten.com”,};
LongTermCredential LongTermCredential=新的长期凭证(“来宾”、“anon”);
用于(字符串主机名:主机名)
代理addCandidateHarvester(新TurnCandidateHarvester(新传输地址(主机名、端口、传输.UDP)、长期凭证));
//为代理构建流
IceMediaStream=agent.createMediaStream(“数据”);
试一试{
组件c=agent.createComponent(stream、Transport.UDP、port、port+100);
字符串响应=”;
List remoteCandidates=c.getLocalCandidates();
for(候选人可以:远程候选人){
响应+=“| |”+can.toString();
}
response=“Video | |”+agent.getLocalUfrag()+“| |”+agent.getLocalPassword()+“| |”+c.getDefaultCandidate().toString()+response;
System.out.println(“服务器>>>”+响应);
DataOutputStream outStream=新的DataOutputStream(client.getOutputStream());
outStream.write(response.getBytes(“UTF-8”);
冲水;
List streams=agent.getStreams();
对于(IceMediaStream localStream:streams){
List localComponents=localStream.getComponents();
对于(组件localComponent:localComponents){
对于(int i=3;i“候选者”和“*”。
localComponent.addRemoteCandidate(新的RemoteCandidate(新的传输地址(细节[4],整数.valueOf(细节[5]),传输.UDP),c,CandidateType.HOST_候选者,基础[1],长.valueOf(细节[3]),null));
}
字符串[]defaultDetail=info[3]。拆分(“”);
字符串[]defaultFoundation=defaultDetail[0]。拆分(“:”;
localComponent.setDefaultRemoteCandidate(新的RemoteCandidate(新的传输地址)(defaultDetail[4],Integer.valueOf(defaultDetail[5]),Transport.UDP),c,CandidateType.HOST_CANDIDATE,defaultFoundation[1],Long.valueOf(defaultDetail[3]),null);
}
setRemoteUfrag(info[1]);
setRemotePassword(信息[2]);
}
agent.startConnectionEstablish();
System.out.println(“ICEServer已完成”);

我现在意识到,您的TURN服务器列表似乎大部分实际上都是STUN服务器(不确定前两个)。如果有任何问题,应将它们添加为STUN服务器:

 agent.addCandidateHarvester(
   new StunCandidateHarvester(
       new TransportAddress(
           InetAddress.getByName('stun.l.google.com'),
           19302,
           Transport.UDP)));

我开始认为4G不允许向任何一个方向发送UDP数据包,这会导致失败…不确定输出如何匹配代码,因为代码显示使用TurnCandidateHarvester而不是StunCandidateHarvester来处理Stunt服务器。谷歌Stunt服务器似乎是端口19302,而不是其一部分url,不太确定…我尝试UDP查看它是否有效,但我认为我也有问题,但我没有深入研究它。你知道吗
Agent agent = new Agent();
        agent.setControlling(false);

        StunCandidateHarvester stunHarv = new StunCandidateHarvester(new TransportAddress("sip-communicator.net", port, Transport.UDP));
        StunCandidateHarvester stun6Harv = new StunCandidateHarvester(new TransportAddress("ipv6.sip-communicator.net", port, Transport.UDP));

        agent.addCandidateHarvester(stunHarv);
        agent.addCandidateHarvester(stun6Harv);
        String[] hostnames = new String[] { "130.79.90.150",
                "2001:660:4701:1001:230:5ff:fe1a:805f",
                "jitsi.org",
                "numb.viagenie.ca",
                "stun01.sipphone.com",
                "stun.ekiga.net",
                "stun.fwdnet.net",
                "stun.ideasip.com",
                "stun.iptel.org",
                "stun.rixtelecom.se",
                "stun.schlund.de",
                "stun.l.google.com:19302",
                "stun1.l.google.com:19302",
                "stun2.l.google.com:19302",
                "stun3.l.google.com:19302",
                "stun4.l.google.com:19302",
                "stunserver.org",
                "stun.softjoys.com",
                "stun.voiparound.com",
                "stun.voipbuster.com",
                "stun.voipstunt.com",
                "stun.voxgratia.org",
                "stun.xten.com",};

        LongTermCredential longTermCredential = new LongTermCredential("guest", "anon");

        for (String hostname : hostnames)
            agent.addCandidateHarvester(new TurnCandidateHarvester(new TransportAddress(hostname, port, Transport.UDP), longTermCredential));

        //Build a stream for agent
        IceMediaStream stream = agent.createMediaStream("data");
        try {
            Component c = agent.createComponent(stream, Transport.UDP, port, port, port+100  );
            String response = "";
            List<LocalCandidate> remoteCandidates = c.getLocalCandidates();
            for(Candidate<?> can : remoteCandidates) {
                response += "||" + can.toString();
            }
            response = "Video||" + agent.getLocalUfrag() + "||" + agent.getLocalPassword() + "||" + c.getDefaultCandidate().toString() + response;
            System.out.println("Server >>> " + response);
            DataOutputStream outStream = new DataOutputStream(client.getOutputStream());
            outStream.write(response.getBytes("UTF-8"));
            outStream.flush();

            List<IceMediaStream> streams = agent.getStreams();
            for(IceMediaStream localStream : streams) {
                List<Component> localComponents = localStream.getComponents();
                for(Component localComponent : localComponents) {
                    for(int i = 3; i < info.length; i++) {
                        String[] detail = info[i].split(" ");   //0: Foundation
                                                                //1: Component ID
                                                                //2: Transport
                                                                //3: Priority #
                                                                //4: Address (Needed with Port # to create Transport Address)
                                                                //5: Port # (Needed with Address to create Transport Address)
                                                                //6: -filler: "Type" is next field-
                                                                //7: Candidate Type

                        String[] foundation = detail[0].split(":"); //Turn "Candidate:#" -> "Candidate" and "#". We use "#"

                        localComponent.addRemoteCandidate(new RemoteCandidate(new TransportAddress(detail[4], Integer.valueOf(detail[5]), Transport.UDP), c, CandidateType.HOST_CANDIDATE, foundation[1], Long.valueOf(detail[3]), null));
                    }
                    String[] defaultDetail = info[3].split(" ");
                    String[] defaultFoundation = defaultDetail[0].split(":");
                    localComponent.setDefaultRemoteCandidate(new RemoteCandidate(new TransportAddress(defaultDetail[4], Integer.valueOf(defaultDetail[5]), Transport.UDP), c, CandidateType.HOST_CANDIDATE, defaultFoundation[1], Long.valueOf(defaultDetail[3]), null));
                }
                localStream.setRemoteUfrag(info[1]);
                localStream.setRemotePassword(info[2]);
            }
            agent.startConnectivityEstablishment();
            System.out.println("ICEServer <><><> Completed");
 agent.addCandidateHarvester(
   new StunCandidateHarvester(
       new TransportAddress(
           InetAddress.getByName('stun.l.google.com'),
           19302,
           Transport.UDP)));