Hello
I am try trying to build a server tcp That can listen on port 6060 from a
GPS tracker. The problem is that I get nothing.
I want to know where is the problem in my code.
Here is my code:
var net = require('net');
var parser = require('socket.io-parser');
var Connections = []; // Keep track of the chat clients
net.createServer(function (socket) {
// Handle incoming messages from clients.
socket.on('data', function (data) {
console.log("connexion etablie");
console.log(socket.name +"connexion");
var packet = parser.Parse_data(data.toString('hex'));
if (packet.Command == 1) {
if (!socket.name) {
socket.name = packet.IMEI;
console.log(packet.IMEI + ' Connected ');
Connections.push(socket);
}
var v = new Buffer("0002640113BC", "hex");
socket.write(v);
for (var i = 0; i < packet.Records.length; i++) {
//db.po_insert({
// IMEI: packet.IMEI,
// record: packet.Records[i]
//});
// push.pushtoserver({
// IMEI: packet.IMEI,
// record: packet.Records[i]
// });
}
}
else if (packet.Command == 7) {
console.log("#################### " + packet.response + "
####################");
}
});
socket.on('end', function () {
console.log(socket.name +" disconected !!");
Connections.splice(Connections.indexOf(socket), 1);
//if (socket.device != null) {
// socket.device.State = false;
//}
});
socket.on('error', function (exception) {
console.log('SOCKET ERROR');
socket.destroy();
});
socket.on('close', function (had_error) {
if (had_error) {
console.log(socket.name+ " disconected !!");
Connections.splice(Connections.indexOf(socket), 1);
}
});
}).listen(6060); //listen for server
console.log("ecoute sur le port 5000");//.listen(5100);
Thanks
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/54965d96-9066-4307-9e19-ea5327ba85a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.