• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket creation freezes (blocks?) program when device is off.  RSS feed

 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program communicates with a wifi device over my home LAN. It works great! HOWEVER, if I turn OFF my device, then try to access it, the program freezes on the sock = new Socket (...) command, even though it is in a try-catch block (for IOException)! The LogCat indicates that the line impl.close() in the Socket.class is last tried. Why won't it trigger an exception instead of freezing?
(BTW, I put the socket setup into an AsyncTask so it won't stop the UI. However, not being able to display what's happened is annoying!) Ideas? Thanks!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Purcell wrote:My program communicates with a wifi device over my home LAN. It works great! HOWEVER, if I turn OFF my device, then try to access it, the program freezes on the sock = new Socket (...) command, even though it is in a try-catch block (for IOException)! The LogCat indicates that the line impl.close() in the Socket.class is last tried. Why won't it trigger an exception instead of freezing?
(BTW, I put the socket setup into an AsyncTask so it won't stop the UI. However, not being able to display what's happened is annoying!) Ideas? Thanks!


Not sure if this will work -- but you can try to connect with a timeout. This is done by creating an unconnected socket, and using the connect() method.

The connect() call will still hang, but it is a limited to a specified (max) period.

Henry
 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, that worked perfectly! You triggered a Why-didn't-I-think-of-that? moment! :-) L.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!