Technologies for Instant Messaging App

Asked

Viewed 960 times

1

I want to develop an Android app(native) instant messaging as Whatsapp for my TCC, I would like to know what technologies for the Java platform offer support for this type of communication, some API etc.

My main question is about real-time communication, such as having a direct channel between two devices, it would take a server to mediate communication?

I did a lot of research and found the XMPP standard, someone knows some library/framework that would make it easier to create a Java application?

What I need is a guide to create the right architecture, from the server to the App.

  • Hello Jadson. Welcome to Sopt. The question is fair, but I have the impression that it is still a little wide for the site. Have you read [Ask]? I think the chances of you having better answers would increase if you asked the more specific question about some aspect you have doubt about (for example, how to create TCP/IP communication in Java, or how to send a request to an HTTP server, something like).

  • 1

    Got it @Luizvieira, thanks.

2 answers

5

There are several ways to implement a communication application. However, I will make some considerations.

Real time?

No APP is exactly in real time. Who uses Whatsapp, Google Hangouts or Facebook Messenger knows that often the message delays.

What you probably want is something that sends messages as soon as possible.

Simple architecture

Sending the message

Basically you need your App to send the message via an HTTP request. This is simple and just see the documentation.

Example:

final TextView mTextView = (TextView) findViewById(R.id.text);
...

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Display the first 500 characters of the response string.
        mTextView.setText("Response is: "+ response.substring(0,500));
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        mTextView.setText("That didn't work!");
    }
});
// Add the request to the RequestQueue.
queue.add(stringRequest);

Redirecting the message

On the server side, you need a REST application that receives the HTTP request with the message. It would be good for you to lock this into a database for logging and other features.

The technologies used here can be:

  • Servlets, JAX-RS or Spring Boot to create web services
  • JDBC, JDBC Template or JPA for bank access

Upon receiving the message, your application must, in turn, request an API such as the Google Cloud Messaging to do the push of the message to the devices that are registered to receive it.

An example of a request would be:

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
  "to": "/topics/foo-bar",
  "data": {
    "message": "This is a GCM Topic Message!",
   }
}

Once this is done, Google servers will notify the devices about the message.

To request this API you can use the Apache Http Client library.

Receiving the message

Finally, the messages would be received on the target device(s) in the following method:

@Override
public void onMessageReceived(String from, Bundle data) {
   String message = data.getString("message");
   Log.d(TAG, "From: " + from);
   Log.d(TAG, "Message: " + message);
   // Handle received message here.
}

Of course it is necessary that the devices that will receive the messages have the application and that this application register to receive the messages. Example:

private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}

XMPP

This is a protocol that has implementations in Java, but this will not solve most of your problems, such as push to distribute messages to customers.

Behold this link for some implementations you can use on the server side.

However, as I said, you will still have to implement the entire application and message distribution.

Considerations

This is an example at a very high level. I say this is not an easy task.

I suggest you ask specific questions about every point you have questions about and avoid asking so comprehensively about the technology. Probably no one will do all the work and post a step-by-step here.

2

  • 1

    I use firebase for this very purpose and it’s fantastic, but it has connection limit, in the free plan. In the case of @Jadson I think it’s perfect.

  • Hello. Thank you for your help. The problem is that your answer essentially only has links, and so it is not very good because links can break (and then the answer would be useless to any future user). If you can edit it to provide at least one example of use (in code), then you get my +1. : ) Or, say if you would like a moderator to convert the question into a comment (assuming you still don’t have enough reputation to comment).

Browser other questions tagged

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