A
A
Andrew2015-04-24 00:44:03
Android
Andrew, 2015-04-24 00:44:03

Incoming messages to the socket. What to do?

Greetings.
There is an application that connects to the server and keeps a connection with it.
This is implemented as a service that launches a client in an AsyncTask.
If the phone falls asleep, then after 5-10 minutes the socket stops receiving incoming messages, despite the fact that the server sends them successfully. If you "wake up" the socket with an outgoing message to the server, then after some time (not immediately, 5-10-15-20 seconds) the sent messages will reach the client. The service wakes up with incoming SMS. If an SMS arrives, a request is sent to the server.
For better understanding:

Example 1.
Launched the application. Waited 5-10 minutes. Sent sms to tf. The application sent a request to the server, the server responded, the application did NOT receive a response. I immediately sent a second SMS - the application sent a request to the server, the server answered, the application GOT a response.

Example 2.
Launched the application. Waited... Sent a request from the server. He did not come. Sent SMS, a request from the application came to the server. The server responded. After 10-15 seconds, the client receives the previous request (sent before SMS) and then the response from the server.

I broke my whole brain. Help)

Service code: pastebin.com/twKGic9X

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey, 2015-04-25
@Krost

Generally. As I was explained - the fundamental thing of sockets: the one who opened the connection, he must maintain it. Those. in this case, I limited myself to "ping" (sending a message to a socket) the server once a minute. There is a real nuance that this only works when the phone is connected to the network (usb) (before that it didn’t even work normally), but I will most likely solve this issue through WAKE_LOCK.

A
Armenian Radio, 2015-04-24
@gbg

What problem are we solving? If you "do not sleep" - you need to put wi-fi lock.

K
Kirill Olenev, 2015-04-24
@agent10

1) The role of SMS is not entirely clear here? And how does the service wake up with incoming SMS?
2) Try to set the socket to setKeepAlive(true)
3) As written above, capture PARTIAL_WAKE_LOCK, but not FULL_WAKE_LOCK
And a couple of questions?
1) Why are you using AsyncTask? Why not just Thread?
2) I recommend sniffing traffic with WireShark, for example.. so you'll be sure of something

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question