all.
I have a raspberry pi running a node.JS web app that uses Express to serve up a static html page. The web app simply runs on localhost, on an instance of chrome. The webpage does not need to be accessed by anything but the pi, so I'm essentially using the node environment and html as my UI for the project.
I'm just wondering how I can get data from the GPIO (using onoff npm library) onto the webpage.
Interactions with the GPIO would be considered server side, whilst the HTML webpage and any javascript running on it is client side.
How can I read from a GPIO and update the locally served webpage in realtime?
Thanks!
You need to write some form of web service.
At the simplest level, this will be an HTTP server which generates an HTML document with the data in it on demand.
If you want to get more complicated, poll the server with Ajax and have it return the data to client-side JS.
A step further would involve the use of WebSockets (consider Sockets.io) to push the data to the client.
Related
I have to build a project that connects a Java application with a node.js server. I've already built the server part, it uses MySQL to store values and can process HTTP requests to return them in JSON format.
The Java app must be able to retrieve data from the server and then process it. The thing is, this application must be receiving information constantly from the server because it will be updating frequently.
Any hints on how to start or documentation you recommend to build this?
Thank you in advance.
Suppose I create a client application in html and javascript. Each user in the same building, on the same Local Area Network (LAN) has the client application on its computer. The web app is running in the browser, like you can open a html file in your browser. (Example of what you could type in the adress bar C://users/username/.../app.htm)
Then, one client is the server, like in a multiplayer game where you can play together on the LAN.
Javascript can send http requests or connect via a socket, but you need something like a http adress to get a connection to another device in the LAN, via the LAN-network. This can be easily done in a java* application.
My idea is to create a java program that handles the connection via the LAN.
The application running in the browser has to communicate to the java program, and the java program communicates to the server/clients via the LAN.
Is it possible to create something like this? I think the point is in the communication between the in-browser app and the running java program.
[*] Java not to be confused with javascript
So, is it actually possible to create something which runs in the browser, and can communicate to an independent program on the same device?
I have made a local Java server that communicates with a local HTML web page. The Java server runs with GlassFish on Eclipse mars. (I am using HTML5's websocket class to make the two communicate with each other). Everything is working well. Now, I want to put my website on a domain (so not localhost), but I still want the Java server to interact with the webpage. Of course, this is not possible since the java server is running locally. I tried looking for this but I could not find it: how can I set up a (Java) server that can communicate with a website (which is just not running locally)? I am new to this, so any help is appreciated!
(I have a computer which can be set up as a server).
Thank you
i've created a project(asp.net) - website
The database resides on the client machine.
Flow:
Client opens the website, and submit with the required fields, and then the server would authenticate.
Next, the api what i've created should be transferred to the Client pc, as the database would be accessible only where the client and server at the same system only.
Limitation: cannot move the database to the server, ie making database on the server.
If i'm hosting website on the localhost, everything is running fine, and also m fetching data from the database and i can see it on the browser.
But the same if i'm hosting website on server, m not able to fetch any result.
Is there any method or so, to execute on the client system that would be making connection between the cient browser and database residing on the client system only.
The whole scenario is same as of: bloomberg (what i came to knw about my issue and the bloomberg as a public db to be used issue), where bbg restricts its usage on the web, and bbg is accessble only for the client system for the client n on that client account only.
ON STRAIGHT: is it possible to access the client machine database or an application by browser.
Because i after making opening the website and also making some input and then submit, the call should call api which will access the data to be shown on browser would be from the client pc.(lets say - database resides at client pc)
No, there is no way to access a traditional database on a PC directly from the browser. You'd need a web app in the middle, so that your browser accesses the web app, and this offers indirect access to the database.
If you can install a web app that has access to the PC database, there are interesting ASP.NET and browser technologies to access the data: Web API OData + breeeze.js.
The only alternative would be to use HTML5 Storage databases, but they are still under definition and mostly unsupported. See, for example, this page: HTML5 Features: Storage. An this is not what you're looking for.
The node.js chat example is ubiquitous. However, they all serve the static html page with which the chat feature is integrated.
What about an html page that is served via apache, php, .net, or other which interacts with a node.js based chat server. How would this be implemented?
For instance, the html page contains a form used to login. The form's action points to the node server which provides the authentication and message handling. How does this chat server communicate with the client-side when it is not also providing the static html content?
Yes, it's possible. If I understand you correctly, you'll probably want to use this approach:
Run the apache server on a different port from the node.js server, and have the static server serve the chat page. Then, you have two main options for how to get data from the static page to the node.js server: either use XMLHttpRequest directly from the static page with CORS (you'll need it because you're running from different ports, but it's still possible to have CORS allow from different ports on the same domain but nothing else, so it can still be secure), or have an invisible iframe of the node.js page on the static page, and then send data to it with postMessage, and then the iframe (which is on the same port as the node.js server, as it's being served by node.js) will forward the data from the postMessage to the server with XMLHttpRequest
You can also do a proxy, but it won't be as good for this type of situation I think, because if Apache is running the proxy, it completely erases how node.js does well with comet and things, but if you run node.js as the main server proxying to Apache, it would be easier just to do everything with node, so I'm guessing you don't want that
Here is a simple solution I found that works to add socket.io real-time interactivity to any existing html page, even when that page is hosted on another server.
Include a reference to socket.io in the head of the html page. The IP address and port number should be the location of your node.js server that is running socket.io.
<script src="http://xxx.xxx.xxx.xxx:xxxx/socket.io/socket.io.js"></script>
[NOTE: localhost doesn't work, you must use the actual IP address - don't forget the port]
Then, within a script block on the same html page, open a connection to the socket:
<script>
var socket = io.connect('http://xxx.xxx.xxx.xxx:xxxx');
</script>
That's it, you're connected!