filmout_display/test/test_messages.js

68 lines
1.6 KiB
JavaScript
Raw Normal View History

const net = require('net');
const { resolve } = require('path');
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,
image: resolve('./img/4kSnake.png'),
position : {
x: 100,
y : 100,
w : 320,
h : 320
}
};
console.log('SENDING');
console.log(data);
client.write(JSON.stringify(data));
await delay(2000);
data.action = 2;
delete data.position
2024-05-08 20:07:36 +00:00
data.exposure = [ 4000 ];
console.log('SENDING');
console.log(data);
client.write(JSON.stringify(data));
2024-05-08 20:07:36 +00:00
await delay(6000);
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;
console.log('SENDING');
console.log(data);
client.write(JSON.stringify(data));
});
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);
});