Reputation: 1521
A server that sends info (in this case temperature data, every second) through a socket connection which can be listened to.
The goal being to display temperature and dynamically update the value on a webpage, with javascript.
The server cannot be modified.
Upvotes: 1
Views: 12452
Reputation: 288230
JavaScript can not open arbitrary TCP connections, as that would allow for all kinds of mayhem when combined with services who authenticate based on IP address, or not at all (and are only protected by firewalls). This includes Windows or NFS file shares, your average printer, your average LAN game, your average home router's web interface and lots of enterprise software.
You you cannot really prevent the browser from visiting a malicious site (since that includes visiting a trusted site with malicious ads). If these sites could effect arbitrary TCP connections, they could for example try out every IP address in the RFC 1918 private address ranges, or every IP address in the address range of the organization the client is coming from, and determine what devices you own. That alone would constitute a serious privacy breach, but imagine a malware site finding a printer and then printing out spam in your office once you visit it by accident.
What you can do is use a WebSocket server to translate native TCP to WebSockets. Most Websocket implementations will have such a server as a demonstration app, but you can also use a standalone proxy.
Upvotes: 2
Reputation: 163538
What you need to do is make the connection with PHP, or something else server side, and return the result via AJAX to your JavaScript.
Upvotes: 0