GPRSC протокол связи - PullRequest
       35

GPRSC протокол связи

0 голосов
/ 16 апреля 2019

Недавно я купил трекер, и трекер работает, я создал сервер для трекера. Теперь я хочу создать систему, чтобы получить долготу и широту трекера и отправить значение в Firebase. С тех пор я создал файлы tcpServer и tcpClient, но не могу расшифровать руководство по устройству слежения. это код, который я использовал для настройки клиента и сервера

TcpClient

var net = require('net');

var HOST = 'localhost';
var PORT = 1234;

var client = new net.Socket();

client.connect(PORT, HOST, function () {
    console.log('Client connected to: ' + HOST + ':' + PORT);
    // Write a message to the socket as soon as the client is connected, the server will receive it as message from the client 
    client.write('Hello World!');

});

client.on('data', function (data) {
    console.log('Client received: ' + data);
    if (data.toString().endsWith('exit')) {
        client.destroy();
    }
});

// Add a 'close' event handler for the client socket
client.on('close', function () {
    console.log('Client closed');
});

client.on('error', function (err) {
    console.error(err);
});

TCPServer

var net = require('net');

// Configuration parameters
var HOST = 'localhost';
var PORT = 1234;

// Create Server instance 
var server = net.createServer(onClientConnected);

server.listen(PORT, HOST, function () {
    console.log('server listening on %j', server.address());
});

function onClientConnected(sock) {
    var remoteAddress = sock.remoteAddress + ':' + sock.remotePort;
    console.log('new client connected: %s', remoteAddress);

    sock.on('data', function (data) {
        console.log('%s Says: %s', remoteAddress, data);
        sock.write(data);
        sock.write(' exit');
    });
    sock.on('close', function () {
        console.log('connection from %s closed', remoteAddress);
    });
    sock.on('error', function (err) {
        console.log('Connection %s error: %s', remoteAddress, err.message);
    });
};

Документы протокола GPRS выглядят так

enter image description here

enter image description here

enter image description here

...