WEBSERVICE REST - JSON - JAVA

Asked

Viewed 495 times

1

I’m developing an Android app where devices can communicate with each other via messages (Instant messenger).

My application is already connecting with the web service (I developed it using Netbeans) and the web service connecting with the database (Mysql).

I can already register users through the application, sending the information to the Web service and the Web service by registering in the database.

My question is the following, how can I make my application send a message to another user, and the user receive the message instantly.

Making the message arrive on the web service apparently is not difficult, already with the information also to which user.

What I’m unable to think about is how the client (Android App) will understand that a message has arrived for him. How the web service will send the message to the user specified in it.

Use JSON for information exchange.

  • If I’m not mistaken you already had a similar question and a very cool answer, I’ll try to find it for you

  • found, might help you http://answall.com/questions/113817/technologias-para-app-de-mensagens-instant%C3%A2neas/113867#113867

  • a form of the client "understand" and is the one I usually see being used is the client continuously identify and "ask" to the server if there are new messages for it, you have created services usually for instant messages are used sockets to keep a single connection, with the Rest Voce will have to open a new connection every time, it will be more expensive

  • I understand, I will study then on sockets, but you know if I program through these sockets, and then I want to develop the same application for iOS, it would be possible to make the connection also of the same ?

1 answer

1

I believe that developing an efficient solution to send messages from the server to Devices, in addition to being particularly complex, requires a structure that conventional http does not contemplate. This is definitely not the way you need to go, unless you have some advanced structure like Amazon AWS and plenty of experience.

Mobile developers know this difficulty and have created solutions to solve this issue without driving any developer crazy. On android we have the GCM (Google Cloud Message), that sends messages up to 2kb to the specified device or Devices.

There are many stages to demonstrate here, but the logic is as follows.

  1. Every android device by default when connecting to the internet has a unique signature registered on google servers.
  2. When your app registers on your server you log the device signature
  3. By signing your server creates the message (with a maximum of 2kb) and sends it to the Google GCM servers
  4. GCM servers have direct access to all connected servers. They therefore send the message to the device.
  5. The device processes the message that can be complete, or only a connection request to download more complex information.
  6. If the need exists the device connects again to your server, to complete the operation by downloading for example.

As you can see, these are some necessary steps. Google offers all the documentation for you, but unfortunately not found in Portuguese.

Of course there are other alternatives. Some paid services such as parse.with They solve all server logistics, but there’s a cost to that. There are also some open source solutions that propose to offer a server structure that is already suitable for mobile needs. A project that may have a promising future is the baasbox, but I don’t know how he behaves in a production environment.

Anyway, I hope I helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.