简体   繁体   中英

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. But the thread that opened the connection will not through any kind of exception since I included a 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 . 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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