-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_sample.js
44 lines (33 loc) · 1011 Bytes
/
client_sample.js
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
41
42
43
44
var net = require('net');
var client = new net.Socket();
var vendor = '__YOUR_COT_VENDER_ID__';
var device = '__YOUR_COT_DEVICE_ID__';
var uuid = '__YOUR_COT_HOST_UUID__'; //your UUID
var auth_token = '__YOUR_COT_TOKEN__';
var owner = '__YOUR_COT_OWENER_ID__';
var group = '__YOUR_COT_GROUP_ID__';
var remote_ip = '__YOUR_COT_SMQ_SERVER_IP__';
var remote_port = __YOUR_COT_SMQ_SERVER_PORT__;
client.connect( remote_port , remote_ip, function() {
console.log('Connected');
client.setEncoding('utf8');
client.write(JSON.stringify({
vendor: vendor,
device: device,
uuid: uuid, //your UUID
token: auth_token,
action: 'update'
}));
client.end( JSON.stringify({
uuid: uuid, //your UUID
action: 'close'
}), 'utf8' );
});
client.on('data', function(data) {
console.log('Received: ');
console.log( data );
client.destroy(); // kill client after server's response
});
client.on('close', function() {
console.log('Connection closed');
});