1

我有一个关于网络的非常奇怪的问题。我创建了一个安全连接到 PC 上运行的服务器的 andorid 应用程序。请注意,尽管 PC 在 NAT 之后,但相应的端口已被转发。还将 PC 放入 DMZ 以避免任何端口转发问题。

问题是,当我通过 WIFI 使用代码时,它工作得很好,但是,在 3G 上,它几乎总是(30 个中的 29 个)阻塞在 SSLSocket 的 getOutputStream 方法中(在服务器端发生了接受)。

你能帮我解决这个问题吗?

谢谢

客户端代码:

E.log("establishing connection: trying to create context");

SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[]{new X509TrustManager(){
        public void checkClientTrusted(X509Certificate[] chain,
                        String authType) throws CertificateException {}
        public void checkServerTrusted(X509Certificate[] chain,
                        String authType) throws CertificateException {}
        public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
        }}}, new SecureRandom());

E.log("establishing connection: trying to create socket factory");

SSLSocketFactory factory = (SSLSocketFactory) context.getSocketFactory ();

E.log("establishing connection: trying to create socket");

kkSocket = (SSLSocket) 
        factory.createSocket(host, Integer.parseInt(port));

E.log("establishing connection: trying to create out writer");
out = new PrintWriter(kkSocket.getOutputStream(), true);

E.log("establishing connection: trying to create in reader");                   
in = new BufferedReader(new InputStreamReader
           (kkSocket.getInputStream()));

失败日志:

04-15 00:07:59.066: E/Bubu(17340): starting thread
04-15 00:07:59.076: I/System.out(17340): Mon Apr 15 00:07:59 CEST 2013 - establishing connection: trying to create context
04-15 00:07:59.076: I/System.out(17340): Mon Apr 15 00:07:59 CEST 2013 - establishing connection: trying to create socket factory
04-15 00:07:59.076: I/System.out(17340): Mon Apr 15 00:07:59 CEST 2013 - establishing connection: trying to create socket
04-15 00:07:59.146: D/dalvikvm(17340): GC_CONCURRENT freed 190K, 5% free 7530K/7880K, paused 4ms+2ms, total 23ms
04-15 00:08:01.056: I/System.out(17340): Mon Apr 15 00:08:01 CEST 2013 - establishing connection: trying to create out writer

成功:

04-15 00:13:15.506: E/Bubu(17750): starting thread
04-15 00:13:15.526: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - establishing connection: trying to create context
04-15 00:13:15.536: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - establishing connection: trying to create socket factory
04-15 00:13:15.536: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - establishing connection: trying to create socket
04-15 00:13:15.556: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - establishing connection: trying to create out writer
04-15 00:13:15.746: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - establishing connection: trying to create in reader
04-15 00:13:15.746: I/System.out(17750): Mon Apr 15 00:13:15 CEST 2013 - from server:bubu
4

0 回答 0