Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点在侦听时挂起_Node.js_Express_Socket.io - Fatal编程技术网

Node.js 节点在侦听时挂起

Node.js 节点在侦听时挂起,node.js,express,socket.io,Node.js,Express,Socket.io,我有一个节点服务器,它正在从一个网页获取数据-(几个整数)-一旦它接收到数据,我希望它处理数据,同时仍然侦听接收到的新数据的更新。 我的问题是,服务器代码似乎在等待数据的到来——所以它有点挂断了。 下面是我的节点服务器代码片段。等待似乎就在插座附近。在线。 是否有什么可以做的,以允许其他任务完成,同时仍在侦听接收到的新数据 var express = require('express'); var app = express(); var server = require('http

我有一个节点服务器,它正在从一个网页获取数据-(几个整数)-一旦它接收到数据,我希望它处理数据,同时仍然侦听接收到的新数据的更新。 我的问题是,服务器代码似乎在等待数据的到来——所以它有点挂断了。 下面是我的节点服务器代码片段。等待似乎就在插座附近。在线。 是否有什么可以做的,以允许其他任务完成,同时仍在侦听接收到的新数据

  var express = require('express');
  var app = express();
  var server = require('http').createServer(app);
  var io = require('socket.io')(server); //require socket.io module and pass the
  var path = require('path');
  var Gpio = require('pigpio').Gpio, //include pigpio to interact with the GPIO
  ledRed = new Gpio(4, {mode: Gpio.OUTPUT}), //use GPIO pin 4 as output for RED
  ledGreen = new Gpio(17, {mode: Gpio.OUTPUT}), //use GPIO pin 17 as output for
  ledBlue = new Gpio(27, {mode: Gpio.OUTPUT}), //use GPIO pin 27 as output for B
  anglev = 0, //set starting value of RED variable to off (0 for common cathode)
  speedv = 0.0, //set starting value of GREEN variable to off (0 for common cath
  dirv = 0, //set starting value of BLUE variable to off (0 for common cathode)
  stopv = 0, // if this is set to 1 then stop the turntable at preset stopping p
  refv = 1,// if this is set to 1 then log the info when the turntable goes by r
  newspeed = 0; //this is the conversion of the speed from 0-6 to 0-255 for pwm

app.use(express.static(path.join(__dirname, 'public')));

app.get('/', function(req, res) {
    res.redirect('index.html');
});

  server.listen(8080);

  io.on('connection', function (socket) {
    socket.on('rgbLed', function(data) { //get light switch status from client -
               console.log(data); //output data from WebSocket connection to con
               anglev=parseInt(data.angle);
               speedv=parseFloat(data.speed);
               dirv=parseInt(data.direction);
               stopv=parseInt(data.stop);
               refv=parseInt(data.refv);
               newspeed = Math.round(speedv * 42.5);
               ledRed.pwmWrite(newspeed); //setspeed
    });
});