Task:

You need to write a simple Real-time application on Android. The application can be installed on any device and contains the following components:

  • EditText (Enter text string)
  • Button (Press the button to save the string in the database on the remote server )
  • List (Update the list by adding this line on all devices where the application is installed)

Firebase type buns are prohibited .

Lecture hall:

The application will be installed on 3000-5000 devices.

Description of the problem:

I did not come across the development of such projects. The web is about using WebSocket to solve this problem. Thus, I am concerned about 2 questions, namely:

  1. What is the best way to write a server and how to connect it with a database? It is clear that this case was in conjunction with Websocket-s. Maybe I was looking badly, but I did not meet examples of such a bundle on the net.

  2. How to update the list on other devices where the application is installed? I understand that I need to register device IPs and send them a response from the server. Otherwise, how can I find out who needs to be updated? But is it true or not, I want to find out.

I will welcome any suggestions! Thank.

  • websocket + json rpc - Sviat Volkov

1 answer 1

Once the question is common, I will also answer general.

Server part

I would choose node.js for the server part, since there are quite suitable implementations of the web socket on it, and would use mongo db with it. It will be quite simple to set it up.

Client part

As for the client part - make sly. While the application is open, keep the connection to the server open and update everything you need in real-time. In the background (if you need to send notifications to the user), you can periodically open a connection, ask the server everything you need, and if there are updates, update the data in the application and send a notification to the user.

When the user deploys the application - connect to the server, update, keep the connection.

Keep in mind that in all cases the client is the initiator of the connection. Connecting from the server to the client is completely meaningless and often difficult, because clients often do not have a white ip and / or they sit behind nat .

  • Thank you very much for your answer! On the server side account: in principle, I also thought about the Node.js + MongoDB bundle. Can you recommend a suitable implementation of the website? At the expense of the client part: If the application is running in the background, do I need to write a Service and open the connection to the server in it? And such a question , why would you advise starting the development of such a system? - Tomas
  • @Tomas is not a suitable implementation, because I did not have to try different ones. To work in the background, you need to create a service, yes. But if you do not need to update the data as soon as they change on the server, then it is better not to keep the connection open, but open it periodically and poll the server. This will help reduce battery consumption. I advise you to start with the study of websocket, because to open it, for example, from java, you need a good idea to steam up with all sorts of certificates, as far as I remember. And anyway, are you sure that you want to use a web socket, and not, say, a simple tcp connection? - selya
  • I just understood a little bit about the website. Um, and how to open a tcp connection and what is better? Will there still be a web socket on the server? If I’m not mistaken, web sockets is just running on top of tcp .... - Tomas
  • one
    @Tomas Web Socket on top of tcp, moreover, the websocket connection is initialized using an http request. Web Socket is used in browsers due to browser policies. If your client is not a browser, but an Android application, then you can (and I would say that you should) use tcp. With the webcast you will have additional data from the ws package to fly, besides, you need to configure certificates, establish connections as required by the ws standard, and so on. In general, where you can do without websockets, you should not use them. - selya
  • one
    @Tomas socket.io runs on top of the websocket. You can easily use it, but why complicate the project with unnecessary dependencies, if you can make it easier? In this case, for weight there is a class Socket in java and a net module in node.js. In addition, you can do without node.js at all by writing a server to java. Bd choose to taste. As for setting up the tcp connection java-java, java-node.js - ask a question with the appropriate topic if you have any questions. - selya