Push data from database to flask web app and Android device - android

How can I show real time database changes in a flask website?
Like on_update and on_insert, the data will be pushed to the website for the user to see.
I want to get alert from an IOT device and insert it to the database and the users who are subbed to that device should get the real-time alerts.
So I thought
>IOT detects
>HTTP POST to database
>Flask App detects the database change
>push to clients on web app and android
I made a web app that queries the DB with flask-sqlalchemy but thats it, these are supposed to be real-time alerts! I'm so frustrated it's been a week. I am going nowhere and I feel so lost now.
>polling
>web sockets
>SSE
>flask sse
>use AJAX
>use JQUERY
HHHOOOOOWWWWW?????? Most of the examples are for chat apps, and I see NO method where you listen to database changes and send it to clients ;(

A very easy way to implement this is using an event SaaS like pusher.com. This should get you set up in no time. They have examples for many different languages and it should fit your need perfectly.
You mention that you see so many chat-apps as examples. This is pretty normal as they are almost the "hello-world" of event-based systems. And that's exactly what you are looking for. An event happens and you want to trigger something on that event.
For chats, the event is: "The user entered a message" and the triggered action is: "Display it to every connected/subscribed user".
Next to a hosted service like pusher.com, you can roll your own. All the required technology are free and open standards. You could use websockets or WebRTC for this. Websockets is easier but it's trickier if you have many open channels. On the other hand, WebRTC scales but it's a bit more complicated to set up. But you won't need video or audio which makes it easier.
You mention "polling" and I am not sure whether you mean "normal" polling or long-polling as in Comet. That is of course an option. It is the easiest solution, but not the cleanest.
SSE seems like a valid option as well. Although I have no personal experience with it yet. But it seems like it's designed for this use-case.
AJAX and jQuery are less related. AJAX is just an umbrella term for programming using XmlHTTPRequest and is used in all solutions mentioned above. jQuery is just a JS framework and is completely unrelated to the task.
long story short: All your mentioned options allow you to do this. I would suggest looking at pusher.com to get started. And their examples have exactly what you need. Their free plan is already really generous for personal projects. If your application outgrows the free plan you can either pay, or roll your own solution.

Related

possible application servers for a chess game (android+web)

I'm making a chess game,playable from both, an android device as well as a web browser.I will take input from user in a UI, & processing of that input-updating gamestate should happen at backend/application server.The response from server goes back to UI which displays the new gamestate.
Now my question is, what are possible options for application server I can explore to actually do this ?I'm not asking which is best or likewise....I just want to know what application servers are there which I can use to make my game.
I've made a similar application in netbeans using glassfish,but this time, I want an android device to be able to communicate with server too, so I'm confused how to approach this.
I've already tried google play services,but additional data about player,his statistics,etc needs to be stored client side,which I dont want.
Please suggest some alternatives.

Best method to store and read data from a cloud source in Android?

The situation: I have many real life locations with specific information associated with them, and updated frequently. I am unsure of how to store this information for use in an android application.
My original thought was storing the data on some server/cloud source/database, reading from the server from each Activity in the app to make sure the info is up to date, and update the server with any changes that may or may not have been made.
For example: there are 200 people inside the library, one person leaves.
So we would read the number of people from the server, display this on the app, person leaves, subtract one, send the new number back to the server.
Would this be an incorrect approach? I'm fairly new to Android in general, and I really have no experience on how to approach this type of situation, what services to use, etc.
I would look into using Parse, its a pretty sweet way to power the backend, and their website is very detailed in explaining how to use it.

How to implement a fast responding android application

I'm doing an android application much like the gmail app for android. I can see the app is very fast and very responsive.
I'm sure gmail uses local caching for better performance. But I wonder how does gmail does the following use cases.
Lets say i login for first time and the app loads all email and put in sql lite or any other caching.
use case1
every time i delete or add a star it makes an asyncronous server req to server. this is fine.
use case 2.
how does the app get notified in case the user makes changes from another client. (from a browser).
To download the entire mails will be costly. Lets assume a case in which the user adds a star to a already cached email.
How can we implement the api in such a way that to get only updates which made from other clients. Updates like new email, deleted email, star added, etc. I'm considering the scenario when the user doesn't use the background sync.
This is been bothering me for a long time. Request you guys to let me know some tutorials or links to understand the secret behind the gmail app.
Why don't you look at the gmail web app. That will be using the same/similar design principals (gmail web app is also very fast for me). Then you can apply the same principals. With the web app you can look at the web requests using something like firebug with firefox. Under the Net tab it will show the json of what is being sent across the network. It will also show you the way the request was structured. You wont be able to see how they go about optimally returning the data, but that should be fairly trivial.
I would recommend for returning data that you do the following:
1) create a cache for the most recent page of emails.
2) Updates of new emails will be immediately prefetched into the cache.
3) setup a cache for the next page and previous page of emails.
Essentially what I am saying is:
1) You can look at googles web version which is very visible to plain snooping.
2) You can optimize based on statistical usage of how the user would want to see their emails. This can suggest cache improvements.
What you are asking for in terms of links is harder because your question relates to many general concepts and proriatary software.

SQLiteDatabase hosted on server android

I have an application that uses the SQLiteDatabase as its database, because each application has its own, custom database (well, custom values), for another app I am making, I want to hose a single SQLiteDatabase that every app will access, for example one app adds a row, while another then reads it at a later time.
Is there anyway to do this? Everything I've found has left me believing there is not, but there has to be.
Any ideas?
Update:
I'm not sure if you've quite understood what I'm trying to do, sorry. The apps accessing this db are all the "same" app, but from different phones, for example, the database could be used to store a user id and their favorite color, so another phone could search their user id, and get the color in db with that user id –
I'm sorry if I did not make that clear enough
Of course there is way to do it! There is always a way!
Anywho, what I think you are looking for is a remote server. These can be done in a few way depending on how much money you have.
(1)If you're broke like me all the time, then you can make an extra computer you have at home act as a server for your app. This can cause a few ( :) hehe few) security issues for your home though. Also you will have a lot of traffic on your home network.
(2)Another option it's to get a domain name and web host. Most of the web hosting services I have seen offer database support. So what you could do is hop on, create your database on the web host server then link your app to your server. The cost on that varies based on your needs.
Really though, is your app interfacing with mulitple people? I can't think of a reason you would want this feature on any other phone (device) than your (relative to us customers) device. I rarely hand my device over to others, and never unless it's locked.
SQLite is serverless. In a situation as described there are no guarantees that it will work properly. Your solution is to create a database server that will cater to multiply Android clients simultaneously.
For more information on SQLite see LinuxForu.com and/or SQLite.org

Game server for an android/iOS turn-based board-game

i'm currently programming an iPhone game and I would like to create an online multiplayer mode. In the future, this app will be port to Android devices, so I was wondering how to create the game-server ?
First at all, which language should I choose ? How to make a server able to communicate both with programs written in objective-c and Java ?
Then, how to effectively do it ? Is it good if I open a socket by client (there'll be 2) ? What kind of information should I send to the server ? to the clients ?
Thanks for your time.
EDIT How massively multiplayer'ed will you game be?
Hi Cyril,
as you noticed, there are two main things two consider:
information sent to the server
information sent to the client
There's only one type of information to sent to the server: the user inputs. If you don't do that, you'll encounter headaches over headaches when rogue client will try to send fake data to your server (like saying "My tank now has 100 000 000 armor").
Then what you sent to the client is up to you but it's totally possible to only sent to the client the other player(s)'s input. This is the way to have the absolute minimum and tinies bandwith usage possible. That is how games like Blizzard's Warcraft 3 are doing it. As a bonus, this makes for tiny replay files (because all you need to do to be able to replay a game is the time (and the input) at which each player's input happened).
The one downsides with sending only the other player's input to the client is that it means all the game's logic is present on every client. For some games, this may be an issue because people may cheat by reverse engineering your game and finding flaws. This issue can be mitigated with careful, controlled, randomization (where in addition to the input+time you send input+time+randomness where randomness cannot be guessed by the client in advance.
Another way to do it is to do some logic computation on the server side. Then, obviously, you need to send the result of the server computation to the client. Done correctly, this has the benefit of both preventing cheats and maky piracy impossible (for example nobody managed to play World of Warcraft in the real economy --that is, on the real Blizzard servers-- using a fake licence key).
Regarding the phone-turn-based game server: just look at one top-selling turn-based game are doing it. Take Uniwar for example: works on iPhone and Android. Game server is written in Java "of course".
The one thing to realize is that a game like the one you plan to write is entirely deterministic: if you can't easily code a replayer or if you can't easily reproduce any kind of scenario leading to a logic bug, you're doing it wrong.
Note that being determistic doesn't mean you can't add what looks like randomness to your players: it's simply that the randomness shall also be deterministic (for example by simply using a different seed for each game + the time at which player inputs are made as a fake random source).
This is a bit lateral solution to the question asked. One of your options is to use Gamooga (http://www.gamooga.com/) so you donot need to worry about the server side, the sockets, the transport logic etc. You can just concentrate on your game logic and just develop that than the required systems stuff.
Gamooga provides you with a realtime communication platform to be used in your games. You can upload your server side message processing scripts to Gamooga's cluster and use its iOS API with in your app to send and receive messages from/to the server side. The server side is auto scaled and managed for you by Gamooga. You can download the SDK and start off with the demos with in the SDK.
Disclosure: I am founder of Gamooga, replying only since its relevant to the question.

Categories

Resources