const http = require('http');
const httpPort = 8766;

const data = JSON.stringify({
    cmdType: 'getAddr',
    addrType: 'server.main'
});

const options ={
    hostname: 'localhost',
    port: httpPort,
    path: '/',
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(data)
    }
}

const req = http.request(options, (res) => {
    console.log(`Status code: ${res.statusCode}`);

    let responseData = '';
    res.on('data', (chunk) => {
        responseData += chunk;
    });

    res.on('end', () => {
        console.log(`Response data: ${responseData}`);
    });
});

req.on('error', (error) => {
    console.error(`Error: ${error.message}`);
});

req.write(data);
req.end();