Nodejs / Socket.emit不工作,找不到数据

问题描述 投票:-1回答:1

所以我现在从Beacon获得uuid和rssi并使用socket.io将其发送到服务器

实际上我得到了必要的数据:当我在客户端测试它显示1:undefined(ed6cfa91cbf1)RSSI-50

但是当我在服务器端测试时,我得到:{mac:undefined,rssi:undefined}

我找不到我的代码中的错误,所以我希望你们能帮助我。

客户端 :

socket.on('connect', function(device){

var noble = require('noble');
var knownDevices = [];

function discovered (peripheral) {

    var device = {
        name: peripheral.advertisement.localName,
        uuid: peripheral.uuid,
        rssi: peripheral.rssi
    };
    knownDevices.push(device);

    console.log(`${knownDevices.length}:${device.name}(${device.uuid})RSSI${device.rssi}`); 

 //working, it show uuid and rssi

    socket.emit(device.uuid ,device.rssi ); //don't working
    }

服务器端 :

   var scanner = io.of('/scanner')

   scanner.on('connection', function(device) {

    let payload = {
        mac: device.uuid,
        rssi: device.rssi
    }
    console.log(payload);

    connection.query("INSERT INTO DataTable values ?", payload,   function(err, rows) {

    })
node.js socket.io beacon
1个回答
0
投票

您是否检查了服务器正在运行的端口以及您在前端建立套接字连接的端口?

简而言之,请确保您的服务器的端口号和前端连接

© www.soinside.com 2019 - 2024. All rights reserved.