Created
May 29, 2019 18:43
-
-
Save bitmorse/e33aeb9a8366c40c6dcb91615e25872a to your computer and use it in GitHub Desktop.
send a message using raw tcp sockets in node js
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
const Net = require('net'); | |
const HologramKey = process.env.HOLOGRAM_KEY | |
const HologramHost = 'cloudsocket.hologram.io' | |
const HologramPort = '9999' | |
let sendWithHologram = function(payload, topic){ | |
let HologramClient = new Net.Socket(); | |
HologramClient.connect({ port: HologramPort, host: HologramHost }, function() { | |
let p = JSON.stringify({"k":HologramKey,"d":payload,"t":topic}) | |
HologramClient.write(p); | |
HologramClient.end(); | |
HologramClient.destroy(); | |
}); | |
HologramClient.on('error', function(ex) { | |
console.log("hologram error"); | |
console.log(ex); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment