Two-way communication between Android and the server

I need a connection between the server and Android. Starting with Android, I need to send my current location coordinates to the server every 10 minutes. I can send a message or image to the server at any time. Similarly, from the server, I want to send data to Android as needed.

What should be the architecture of my application.

Communication with Android on the server and Server to Android is independent of each other, I should not ask about it as a two-way communication, but at the same time I want to communicate on both sides with each other at any time.

Should I use a web service of any type or just network sockets or something else.

+4
source share
2 answers

You can use websockets or ...

Just send the data from the phone to the server using a regular request. If you want to send something from the server to the phone, you can use push notifications ( C2DM ), and if you receive such a push message, you know that the server has data for you and the phone can be downloaded using a regular request; - ) It depends on what data you want to send. Sometimes this approach will be good, sometimes it is better to use web ports, TCP sockets or even XMPP; -)

+3
source

You can use Acknowledge for the same. You need to implement ACK / NACK Logic in your code. When you send data, just wait for the ACK for a certain period of time. If the ACK is not received, you need to send a NACK for it. Here you need to use the session identifier (the type of identifier for communication on both sides, which can be any random number).

You can use this logic on both sides.

0
source

Source: https://habr.com/ru/post/1397731/


All Articles