2024-04-20 01:48:14 +00:00
|
|
|
const net = require('net');
|
2024-05-05 15:28:20 +00:00
|
|
|
const { resolve } = require('path');
|
2024-04-20 01:48:14 +00:00
|
|
|
|
|
|
|
const serverAddress = 'localhost';
|
|
|
|
const serverPort = 8081;
|
|
|
|
|
|
|
|
const client = new net.Socket();
|
|
|
|
|
|
|
|
console.log(`Connecting to ${serverAddress}:${serverPort}...`);
|
|
|
|
|
|
|
|
async function delay (ms) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return setTimeout(resolve, ms);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
client.connect(serverPort, serverAddress, async () => {
|
|
|
|
const data = {
|
|
|
|
action : 1,
|
2024-05-05 15:28:20 +00:00
|
|
|
image: resolve('./img/4kSnake.png'),
|
|
|
|
position : {
|
|
|
|
x: 100,
|
|
|
|
y : 100,
|
|
|
|
w : 320,
|
|
|
|
h : 320
|
|
|
|
}
|
2024-04-20 01:48:14 +00:00
|
|
|
};
|
|
|
|
console.log('SENDING');
|
2024-04-20 02:33:28 +00:00
|
|
|
console.log(data);
|
|
|
|
client.write(JSON.stringify(data));
|
2024-04-20 01:48:14 +00:00
|
|
|
await delay(2000);
|
2024-04-20 02:33:28 +00:00
|
|
|
data.action = 2;
|
2024-05-05 15:28:20 +00:00
|
|
|
delete data.position
|
2024-05-08 20:07:36 +00:00
|
|
|
data.exposure = [ 4000 ];
|
2024-05-05 15:28:20 +00:00
|
|
|
console.log('SENDING');
|
|
|
|
console.log(data);
|
|
|
|
client.write(JSON.stringify(data));
|
2024-05-08 20:07:36 +00:00
|
|
|
await delay(6000);
|
2024-05-05 15:28:20 +00:00
|
|
|
data.action = 1;
|
|
|
|
data.position = { x: 50, y : 50, w : 320, h : 320 };
|
|
|
|
console.log('SENDING');
|
|
|
|
console.log(data);
|
|
|
|
client.write(JSON.stringify(data));
|
|
|
|
await delay(1000);
|
|
|
|
data.action = 2;
|
|
|
|
delete data.position;
|
2024-05-08 20:07:36 +00:00
|
|
|
console.log('SENDING');
|
|
|
|
console.log(data);
|
|
|
|
client.write(JSON.stringify(data));
|
|
|
|
await delay(2000);
|
|
|
|
data.action = 3;
|
2024-04-20 01:48:14 +00:00
|
|
|
console.log('SENDING');
|
2024-04-20 02:33:28 +00:00
|
|
|
console.log(data);
|
|
|
|
client.write(JSON.stringify(data));
|
2024-04-20 01:48:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on('data', (data) => {
|
|
|
|
console.log('RECEIVED');
|
|
|
|
console.log(data.toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('close', () => {
|
|
|
|
console.log('Closing connection');
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('error', (err) => {
|
|
|
|
console.error('Error:', err);
|
|
|
|
});
|