java.net.sockttimeout,如何调试SocketTimeoutException?

当客户端A尝试连接到服务器B时,出现java.net.SocketTimeoutException。问题可能由于弱互联网信号导致请求超时。为解决此问题,可以增加连接和读取超时设置。如果网络连接持续不稳定,建议在调用其他必需函数之前先测试服务器连接。如果测试函数也遇到SocketTimeoutException,则提示用户‘网络连接弱’。
摘要由CSDN通过智能技术生成

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..

解决方案

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);

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!".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值