42 lines
914 B
JavaScript
42 lines
914 B
JavaScript
const net = require('net');
|
|
|
|
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: 'filename.tif',
|
|
};
|
|
console.log('SENDING');
|
|
console.log(data);
|
|
client.write(JSON.stringify(data));
|
|
await delay(2000);
|
|
data.action = 2;
|
|
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);
|
|
}); |