[英]Using Socket.io to pass JavaScript Variables
so I currently have a JavaScript code that I run on my iPhone to pull its Accelerometer data. 因此,目前我有一个在iPhone上运行的JavaScript代码,以提取其Accelerometer数据。 What I would like to do is Pass this data to my Mac Book Pro and use the variables in A python Script. 我想做的就是将这些数据传递到Mac Book Pro,并使用python脚本中的变量。 The Variables are changing multiple times a second so I was thinking of using Socket.io, does anyone know how i would go about this? 变量每秒变化多次,所以我在考虑使用Socket.io,有人知道我会怎么做吗? I would greatly appreciate any help I can get. 我将不胜感激我能得到的任何帮助。 Thank you. 谢谢。
<html>
<body>
<div id="content">
<h1>Accelerometer JavaScript Test</h1>
<ul>
<li>acceleration x: <span id="accelerationX"></span></li>
<li>acceleration y: <span id="accelerationY"></span></li>
<li>Motor Speed: <span id="speed"></span></li>
</ul>
</div>
<script type="text/javascript">
window.ondevicemotion = function(e){
var x = e.accelerationIncludingGravity.x;
var y = e.accelerationIncludingGravity.y;
var newx = x * 100
var newy = y * 100
var finalx = Math.round(x);
var finaly = Math.round(y);
document.getElementById("accelerationX").innerHTML = finalx
document.getElementById("accelerationY").innerHTML = finaly
speed = finalx * 10
document.getElementById("speed").innerHTML = speed
}
</script>
</body>
</html>
in client side you must use socket.emit('key', value);
在客户端,您必须使用socket.emit('key', value);
and in server side you must listen for a key, for example in nodeJS its like this socket.on('key', function(value){});
并且在服务器端,您必须侦听一个键,例如在nodeJS中,就像这个socket.on('key', function(value){});
wow you asked this in a lot of places... I answered it here: 哇,你在很多地方都问过这个...我在这里回答了:
Using Socket.io and iPhone Accelerometer 使用Socket.io和iPhone加速度计
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.