简体   繁体   English

套接字连接问题

[英]Socket Connection Problem

I am using Socket connection to establish connections in my application. 我正在使用套接字连接在我的应用程序中建立连接。 I have a problem when establishing the tunnel with the server: the connection is being closed automatically after 3 minutes for example so when trying again to get data after 3 or 4 minutes, I will have an exception in the inputStream and outputStream. 与服务器建立隧道时出现问题:例如3分钟后连接自动关闭,因此当尝试在3或4分钟后再次获取数据时,inputStream和outputStream中将出现异常。 But the thread that opened the connection will not through any kind of exception since I included a try{ ... } catch (Exception ex) { } . 但是打开连接的线程不会发生任何异常,因为我包括了try{ ... } catch (Exception ex) { }
Now the question is, How to keep alive the socket connection to not close at all? 现在的问题是,如何保持套接字连接完全关闭?

您是否尝试过Socket.setKeepAlive(true)

This issue is disucsse over on BlackBerry support forums . BlackBerry支持论坛上无法解决此问题。 It is important to remember that when using a portable connected wireless device there are many reasons the connection might go down, and having a short timeout may be beneficial in cases where the connection may not be reliable: 重要的是要记住,当使用便携式连接的无线设备时,连接可能会断开的原因有很多,而在连接可能不可靠的情况下,短暂的超时可能是有益的:

  • Fringe areas 边缘区域
  • inside buildings 建筑物内
  • moving 移动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM