如何调试SocketTimeoutException? [英] How to debug SocketTimeoutException?

查看:672
本文介绍了如何调试SocketTimeoutException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户端A连接到服务器B时,我们在服务器B上获得java.net.SocketTimeoutException.不知道为什么.客户端正在向服务器发送数据,然后服务器抛出此异常.一个人如何解决这个问题?

We are getting a java.net.SocketTimeoutException on server B when client A connects to server B. No idea why. The client is sending data to the server and the server then throws this exception. How would one troubleshoot this issue?

请注意,目前仅发生过一次.不知道这是否可复制.尝试再次设置测试.

Note currently this has happened only once. Not sure if this is reproduceable. Attempting to setup the test again..

推荐答案

当我的用户使用3G或2G网络时,我遇到了同样的问题.这意味着,由于互联网信号较弱,您将请求发送到服务器,并且无法建立连接.您可以增加连接的超时时间

I had same problems, when my users used 3G or 2G network. It means, that you send request to server, and can't estabilish connection, because of weak internet signal. You can increase timeouts on your connection

URLConnection connection;
int timeout = 30 * 1000; 
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);

但是,如果您拥有weaaak weeeaaaak互联网connection,则超时对您没有帮助. 我刚刚在WebService中创建了1个testFunction(或者您可以使用其中的一个)来用server测试connection,然后再调用其他必需的函数,如果我得到SockectTimeoutException调用此函数,则只向用户报告通知互联网连接弱!" .

But if you have weaaak weeeaaaak internet connection, timeouts does not help you. I'm just created 1 testFunction in WebService (or you can use one of yours) for testing connection with server before calling another required functions, and if I get SockectTimeoutException calling this function - just report to user notification "Weak internet connection!".

这篇关于如何调试SocketTimeoutException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆