node.js - Gps 设备数据不可编辑
问题描述
我正在使用 BW08 设备跟踪并将数据发送到自己的服务器和用节点 js 编写的服务器。但是设备在我的服务器上发送数据为
*
aD 'T�8
aD 'T�8
*
aD 'T�8.79.48.102: xx
*
xx �
�C��8���n�
xx �
�C��8���n�
如何读取数据?我的NodeJS服务器代码在这里:============================================ =================================
var net = require('net');
var HOST = 'xxx.xxx.x.xxx';
var PORT = 17000;
// Create a server instance, and chain the listen function to it
// The function passed to net.createServer() becomes the event handler for the 'connection' event
// The sock object the callback function receives UNIQUE for each connection
net.createServer(function(sock) {
sock.setEncoding('utf8');
// We have a connection - a socket object is assigned to the connection automatically
console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);
// Add a 'data' event handler to this instance of socket
sock.on('data', function(data) {
console.log('*');
console.log(data.toString('ascii'))
console.log(data.toString());
console.log('*');
console.log('DATA ' + sock.remoteAddress + ': ' + data);
// Write the data back to the socket, the client will receive it as data from the server
sock.write('You said "' + data + '"');
});
// Add a 'close' event handler to this instance of socket
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});
}).listen(PORT, HOST);
console.log('Server listening on ' + HOST +':'+ PORT);
解决方案
推荐阅读
- npm - 如何使用 Vite 向用户显示 package.json 中的当前应用版本?
- python - 在python中使用for循环作为包含str和int的列表的过滤器
- gitlab - 如何在 gitlab ci 中使用另一个变量
- pandas - Postgres有没有办法将数据库中的excel文件存储作为bytea转换为包含真实数据的列表
- python - 如何获得给定磁盘的读/写速度?
- regex - 正则表达式替换以将分页 URL 映射到新格式
- flutter - 在发布 apk 中只能看到 Flutter 灰屏
- android - 多个 Android 应用程序依赖于具有不同布局文件的模块中的相同片段
- sql - 将两个连续的行合并为一列
- docker - Go gRPC on Docker on Cloud Run “传输:拨号拨号 tcp 时出错:i/o 超时”