Created
December 7, 2014 04:40
-
-
Save rexstjohn/dd1991aa149b1fb6f85d to your computer and use it in GitHub Desktop.
TCP socket to CAN Gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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