HTML5 - synchronize local DB with Server - html

I have an application which runs in ofline mode also using browsers local database. Now I want my application to sync this with my server. I want to perform the below tasks
Check for a connection at regular intervals
When I have a connection send data to the server
Get the updated data present on the server.
What should I do to accomplish my above goals?
Is WebSockets a solution to it?

You do not need WebSockets for this. I would suggest simply using XMLHttpRequest. You do need to keep track of what local data is un-synced to the server (either by placing references to un-synced data in a special "queue" when offline or by having a separate field in the local DB saying "synced"). When connected, read unsynced data and submit by XMLHttpRequest.

Related

Firebase Automatic Sync with Local PC

I'm working on a project that can take data from a Weintek HMI, put them on a webserver and then send them to an application that I created on android studio.
I've found firebase that can help me in this task.
In easybuilder that works with my hmi, I can create a mysql database that can store the data.
The problem is how can I update automatically firebase database with mysql database with an interval of time in order to access them on the android app.
If there is no solution with mysql, can someone suggest other method to extract the data and use some web server to sync it with the android app?
I don't know your specific need, in terms of data volume or application, but as a workaround, maybe this can help you:
I usually apply MQTT, which many Weintek HMIs have, to send telemetry data, and then use NodeRed to process and redirect the data to a database, email, SMS, Telegram, CSV, TXT... depending on the need , which in your case could be Firebase (I never used it).
It works great for me as I don't have to worry about HMI limitations.
The problem is the reliability of the data, in terms of confirming that when the HMI sends, the server listens and writes, but there are certainly ways to deal with this, and the fact that you need to have a server with NodeRed running.
If you have never done so, in Weintek HMIs you can send the MQTT payload cyclically using macros easily.

Connecting re-frame app to a Database

I'm having a problem with my re-frame application. I can't figure out how to connect it to a local database on my machine.
In other applications I've written, I've had to add the database specifications (username, password etc) into profiles.clj. Should I create profiles.clj and add the location of my database there? And does this mean I have to update the project.clj as well?
Finally, do the queries to the database, such as GET and POST requests, go in db.cljs.
I apologise if these questions are trivial but after reading the documentation several times I am still a little confused
re-frame is a framework for building client-side web applications. You won't be able to do generic database queries as most databases don't support direct access from a browser.
I'm having a problem with my re-frame application. I can't figure out how to connect it to a local database on my machine.
You probably need to create a middle API tier that accepts REST requests from re-frame, and queries the database, returning JSON back to the client.
Finally, do the queries to the database, such as GET and POST requests, go in db.cljs
Those are probably queries to your API tier? They can live anywhere that you would like.
One thing to clarify: re-frame has an app-db that it uses and refers to. This is a client-side database of local state that lives in your application. It doesn't have a connection to the backend, at least not without you writing more code for it. It sounds like you might be confusing these?

can I get notification in Yii view when database is updating?

I want to receive a notification while Mysql database is updating and this notification should stop when the update finish (by adding "NEW"). I want to know the simplest way to do this .
Any idea please ?
Thanks
Yii, being a mere PHP framework running on the server, can not do such a thing. This is essential to client-server architecture. The server can not take the initiative to update the client.
The client (i.e. the user computer) can take the initiative. It can send a request to the server. Then, and only then, can the server respond to client.
You will need Javascript running on the client. The Javascript polls the server (via ajax) to see if the database is being updated. If javascript polls and finds that the server responds with: "database complete", then Javascript can add the 'NEW' logo.

Synchronize multiple web-servers when using Linq

Today I'm running a single asp.net 4 iis web-server and a single SQL-server. But now i need to start a second web-server to manage the load i get. The problem is when i use Linq the framework caches data from the database on the web-server resulting in the server getting out of sync. i always run (sample) DatabaseDataContext.MyTable.First(some condition) and i always submit the data to the database after changing it, but I still get old data that is cached on the web-server that did not do the change.
How do i solve this, is there any settings like forcing Linq to check last modified or any other checks on the tables involved.
Any ideas or tutorials on how to manage multiple servers and using Linq.
BR
Andreas

Communication between AS3 and MySQL server

I'm developing a game coded in Flash AS3 and need to read/write info to an SQL server.
Currently, for testing purposes, I use ASQL which is very simple and robust, but it needs a direct connection from the client machine to the SQL server (port 3306 open and allowing wildcard username to connect from anywhere using a password) and the worse, the .swf format itself is not encrypted and a all decompilers will let you extract AS3 code, which means a password stored in code.
I have rounded up a few options but they all lack security measures:
AS3 code sending a POST req to a PHP page which connects to the MySQL server
Use amfphp, but the AMF protocol is still sniff-able
Keep current method and force users to have outgoing port 3306 open, which may confuse costumers.
Help/tips/discussion would be highly appreciated.
You can use HTTP(S) with authentication with e.g. PHP. Don't make the script a wrapper to the SQL connection, as this'd ruin the point of the script (essencially); have custom commands as the protocol (e.g. add/update high scores).
Depending on the number of commands needed I think you should choose option 1 (with only one or a few commands) or option 2 (if you have some more and complex commands to send). Don't open your database to the public internet.
What is the problem you are trying to solve/secure? If all your application (game) logic is at the client you cannot prevent people from faking results. The client is never to be trusted and no securing of the line (https or any other encryption of the communication) will help that -- that will only keep other people from eavesdropping.
If you are trying to secure the posting of high scores or game state - to my knowledge you can make it hard to fake them but you cannot make it impossible unless you move at least some game logic to the server.