Call server side C++ from webpage - javascript

I would like to use node.js/express and socket.io to retrieve data off of a piece of hardware through a web browser, but I really dont know where to start. I currently have express serving a webpage. I would like to retrieve and display raw data in realtime (graph form) from a sensor, for this reason, socket.io looked promising. I would also need to use some server side code (c, c++?) to do some processing on this data and display the results on the page. Is Ajax the best way to do this?
I do not really have much experience with this sort of thing, so is this the best way to go about this? Better options?

you can use web sockets and this c++ library. http://libwebsockets.org
and there is pretty example of its usage. http://martinsikora.com/libwebsockets-simple-http-server

Related

Bridging a Python back-end and JavaScript front-end

I'm currently working on a project that involves parsing through a user-supplied file, doing computations with that data, and visualizing the results using graphing utilities. Right now, I'm stuck with using Python as the back-end because it has scientific libraries unavailable in JavaScript, but I want to move the entire tool to a web server, where I can do much slicker visualizations using D3.js.
The workflow would be something like: obtain the file contents from the browser, execute the Python script with the contents, return jsonified objects of computed values, and plot those objects using D3. I already have the back-end and front-end working by themselves, but want to know: How can I go about bridging the two? From what I've gathered, I need to do something along the lines of launching a server, sending AJAX requests to the server, and retrieving data from the server. But with the number of frameworks out there (Flask, cgi, apache, websockets, etc.), I'm not really sure where to start. This will likely only be a very simple web app with just a file submit page and a data visualization page. Any help is appreciated!
Apache is a web server, flask is a web framework in python, websockets are a protocol, and cgi is something totally different, and none of them help you on the front end.
You could deploy a simple backend in flask or django or pylons or any other python web framework. I like django, but it may be a little heavy for your purpose, flask is a bit more lightweight. You deploy them to a server with a web server installed and use something like apache to distribute.
Then you need a front end and a way of delivering your front end. Flask / Django are both fully capable of doing so in conjunction with a web server, or you could use a static file server like Amazon S3.
On your front end, you need to load D3 and probably some kind of utility like jQuery to load and parse your data from the back end, then use D3 however you like to present it on screen.
Flask is easy to get up and running and is Python based. It works well with REST APIs and data sent by JSON (or JSON API).
This is one solution with which I have some experience and which seems to work well and is not hard to get up and running (and natural to work with Python). I can't tell you whether it is the best solution for your needs, but it should work.
If you are overwhelmed and don't know where to start, you can pick one of the options and google search for a tutorial. With a decent tutorial, you should have an example up and running by the end of the tutorial, and then you will know if you are comfortable working with it and have an idea whether it will meet your needs.
Then you could do a proof-of-concept; make a small app that just handles one small part (the one you are most concerned about handling, perhaps) and write something which will do it.
By then, you can be pretty sure you have a good tool for the purpose (unless you were convinced otherwise by the proof-of-concept -- in which case, try again with another option :-))

React,js App - Getting data using Ajax

I am trying to build a fast React.js app, basically a game.
I need to display 'live' data, but loading them from server using Ajax doesnt feel like the right way to do it. Its React.js, but Ajax isnt the synonym for reacting. I have an idea to use socket.io for this and some kind of backend system for keeping and processing the data, not loading them from database every time.
Is this a good idea or a right way to do a fast React.js app, or am I totally wrong?
Loading data from a server will be faster indeed if loaded from live memory directly instead of traditional database lookup.
Socket.io can be useful if you want to push data from server to client, with server side initiation.
React.js does not make things fast by itself really. It can make development faster.
You can also have a look at Angular-Firebase and 3-way data binding. This is specifically for building real-time applications.
https://www.sitepoint.com/creating-three-way-data-binding-firebase-angularjs/

Connecting DB with my Firefox OS app using JS

I'm developing an app for Firefox OS and I need to retrieve/sent data from/to my DB. I also need to use this data in my logic implementation which is in JS.
I've been told that I cannot implement PHP in Firefox OS, so is there any other way to retrieve the data and use it?
PS: This is my first app that I'm developing, so my programming skills are kind of rough.
You can use a local database in JS, e.g. PouchDB, TaffyDB, PersistenceJS, LokiJS or jStorage.
You can also save data to a backend server e.g. Parse or Firebase, using their APIs.
Or you can deploy your own backend storage and save data to it using REST.
You should hold on the basic communication paradigms when sending/receiving data from/to a DB. In your case you need to pass data to a DB via web and application.
Never, ever let an app communicate with your DB directly!
So what you need to do first is to implement a wrapper application to give controlled access to your DB. Thats for example often done in PHP. Your PHP application then offers the interfaces by which external applications (like your FFOS app) can communicate with the DB.
Since this goes to very basic programming knowledge, please give an idea of how much you know about programming at all. I then consider offering further details.
It might be a bit harder to do than you expect but it can be easier than you think. Using mysql as a backend has serious implication. For example, mysql doesn't provide any http interfaces as far as I know. In other words, for most SQL based databases, you'll have to use some kind of middleware to connect your application to the database.
Usually the middleware is a server that publish some kind of http api probably in a rest way or even rpc such as JSONrpc. The language in which you'll write the middleware doesn't really matter. The serious problem you'll face with such variant is to restrict data. Prevent other users to access data to which they shouldn't have access.
There is also an other variant, I'd say if you want to have a database + synchronization on the server. CouchDB + PouchDB gives you that for free. I mean it's really easy to setup but you'll have to redesign some part of your application. If your application does a lot of data changes it might end up filling your disks but if you're just starting, it's possible that this setup will be more than enough.

DataBase Connectivity on the client side using (JavaScript)

I have a question which really Poked me for several days... I have came across a hurdle, the problem is that i need the Php application on the server side and the database to be on the client side... and the application should communicate with each other very nicely..
Javascript was the best option coming in my mind... The problem is that i dont have any idea how do i make this thing applicable...
If any one have any knowledge for that please share that stuff with me...
Thanks in advance...
Your question is kind of generic, so i can't determine whether you REALLY need a database stored on the client-side, and why. However if that is what you truly desire, HTML5 has client-side storage capabilities which can be used for running apps locally in the browser without having to pass data back to the server:
Some background and usage
Tutorial

Best Way to Transfer Data to and from a MySQL Database

I wonder whether someone may be able to help me please. For a while now I've been working on the Javascript and HTML elements of the Google Maps V3 api. I now want to look at how I'm going to transfer the data to and from MySQL database.
I've read quite a lot of documentation on the Internet on the various methods of transferring this information but I'm not too sure of the best route to take.
I just wondered whether it would be possible that someone with a lot more experience than I could perhaps give me a bit of advice and direction please on the best way to transfer this data.
Many thanks and kind regards
it's a fairly broad question, but mostly dependent on your implementation. Are you already interfacing with the API using a server side language, or just all with Javascript? If everything is being done on the client side, then you would want to consider some sort of AJAX/form functionality to get the data from the client to a server side script. If you are doing any of this on the server side, then you can cut out the AJAX middle man and run SQL commands via PHP or whatnot as you are interfacing with the API.
I would recomend MySQl Dump. Its fairly simple and there is plenty of documentation on how to do it.

Categories