-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeo_remoteControl.js
More file actions
40 lines (30 loc) · 830 Bytes
/
Copy pathmeo_remoteControl.js
File metadata and controls
40 lines (30 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var net = require('net');
var socket = net.Socket();
var readline = require('readline');
var host = '192.168.1.100';
var port = 8082;
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Test if host is an IP address
if(net.isIP(host) == 0 ? console.log('Invalid IP Address.') : '');
// Prompt user for character key
function promptForCharacterKey(callback){
rl.question("> Insert Character Key: ", function (answer) {
callback(answer);
});
}
socket.connect(port, host, function (){
promptForCharacterKey(function (characterKey){
// Sends data on the socket.
socket.write('key=' + characterKey + '\n');
socket.on('data', function (data){
process.exit(0);
});
socket.on('error', function (error){
console.log('Error: ' + error);
});
socket.end();
});
});