简体   繁体   中英

How to stream real time data (numbers) to Android app?

I'm building an Android app in which I want to display some real time data (updated every second) which I want to stream directly from my server to the App. There will be multiple Apps connected at the same time, which should all get the same stream. I am now looking for a way to do this from both the server and the client/Android side. From the server side I can basically build anything, so I thought I'd start from the client side.

In the Android docs I found the inputStream class which I guess is what I need for this. So my first question: is the inputStream class the right tool for the job?

If so, I guess I can set it up (found some examples on the net), but from here I'm still unsure of how to build this service from the server side? Do I need to build a simple page which I constantly update, or should I use a messaging lib such as zeromq with multicasting? Any more tips/hints/pointers on which technology to use for the server side would be very welcome as well!

This depends on your data. For example if you need to keep your clients updated on some values, like weather data in a location, a simple polling mechanism will suffice. You would have to build a web page that shows the current values and the clients would have to keep polling and parsing the page in the time intervals desired.

On the other hand, if you've got a stream of binary data that need to be transferred to the client, you would need to do some socket programming. There are tons of samples like this to help you get started. Also keep in mind that to maintain your sockets with the server, you will have to keep them running in the background as a service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM