Wednesday, March 14, 2012

[android-developers] SocketTimeoutException is not thrown if device screen is locked

I implemented STUN client which sends requests to STUN server with
specified period and during this period listens for requests from STUN
server:

private void waitForNextRequest(int timeout) {
try {

byte[] respData = new byte[1024];
DatagramPacket bRespPacket = new DatagramPacket(respData,
respData.length);
datagramSocket.setSoTimeout(timeout);
datagramSocket.receive(bRespPacket);
processReceivedData(bRespPacket.getData());

} catch (Exception e) {
// ignore
}
}

If device goes into standby mode (when screen turns off) the program
execution freezes on datagramSocket.receive() and no
SocketTimeoutException is thrown until the screen becomes unlocked.
When the screen unlocks, SocketTimeoutException is successfully thrown
and program execution goes on.
What is the reason of such behavior? And how to make
SocketTimeoutException be thrown correctly all the time?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment