Created
November 30, 2016 23:31
-
-
Save tobalsgithub/e10595a08ec275108181adc413c53df9 to your computer and use it in GitHub Desktop.
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 listener = net.createServer(); | |
var port = process.env.PORT || 6980; | |
var sendNack = !!process.env.SEND_NACK; | |
var startBlock = String.fromCharCode(0x0B); | |
var endBlock = String.fromCharCode(0x1C, 0x0D); | |
listener.on('connection', function (socket) { | |
function printEventMessage(event) { | |
console.log(event); | |
} | |
socket.on('end', function () { | |
printEventMessage('end'); | |
}); | |
socket.on('close', function () { | |
printEventMessage('close'); | |
}); | |
var buffer = ''; | |
socket.on('error', function (err) { | |
printEventMessage('error'); | |
console.log(err); | |
}); | |
socket.on('data', function (data) { | |
printEventMessage('data'); | |
console.log(data.toString()); | |
var ack = startBlock; | |
if (sendNack) { | |
ack = ack + 'MSH|^~\\&|REDOX|RDX|||20161130174746||ACK||P|2.3\rMSA|AE'; | |
//ack = ack + 'MSH|^~\\&\nMSA|AE'; | |
} else { | |
ack = ack + 'MSH|^~\\&|REDOX|RDX|||20161130174746||ACK||P|2.3\rMSA|AA'; | |
//ack = ack + 'MSH|^~\\&\nMSA|AA'; | |
} | |
ack = ack + endBlock; | |
setTimeout(function () { | |
socket.write(ack); | |
}, 4000); | |
}); | |
}); | |
listener.on('error', function (err) { | |
console.error('Error in MLLP listener. Error: ' + err.code); | |
}); | |
listener.on('close', function () { | |
console.log('Closed connection on port ' + port); | |
}); | |
listener.listen(port, function () { | |
console.log('Listening on port ' + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment