Skip to content

Instantly share code, notes, and snippets.

@rexstjohn
Created December 7, 2014 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexstjohn/dd1991aa149b1fb6f85d to your computer and use it in GitHub Desktop.
Save rexstjohn/dd1991aa149b1fb6f85d to your computer and use it in GitHub Desktop.
TCP socket to CAN Gateway
var net = require('net');
var HOST = '158.199.141.247';
var PORT = 222;
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('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(new Buffer([0x52,0x43,0x49,0x44,
0x00,0x01,0x00,0x01,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00]));
});
// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
client.on('data', function(data) {
console.log('DATA: ' + data);
// Close the client socket completely
//client.destroy();
});
// Add a 'close' event handler for the client socket
client.on('close', function() {
console.log('Connection closed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment