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.
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.
Share Improve this question edited May 6, 2021 at 9:21 Gunslinger asked Feb 5, 2012 at 23:20 GunslingerGunslinger 1,5417 gold badges22 silver badges36 bronze badges 5- Javascript cannot do TCP. You need server-side help. – zneak Commented Feb 5, 2012 at 23:23
- Take a look at this – andriy Commented Feb 5, 2012 at 23:23
- @zneak - why Javascript cannot do TCP? I see a new standard creeping up Javascript spine: w3/TR/raw-sockets – AlikElzin-kilaka Commented Jul 1, 2014 at 10:04
- possible duplicate of Connecting to TCP Socket from browser using javascript – AlikElzin-kilaka Commented Jul 1, 2014 at 10:05
- @kilaka, this question (and ment) is two years old. You answered your own question by saying that it's new. – zneak Commented Jul 1, 2014 at 17:10
2 Answers
Reset to default 2JavaScript can not open arbitrary TCP connections, as that would allow for all kinds of mayhem when bined 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 ing 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.
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745143702a4613548.html
评论列表(0条)