const dgram = require('dgram');
const client = dgram.createSocket('udp4');

const message = 'www.facebook.com';

// const serverHost = '34.116.211.192';
// const serverPort = 3000;

// const serverHost = '209.97.181.89';
// const serverPort = 33333;

const serverHost = 'localhost';
const serverPort = 33333;


client.send(message, 0, message.length, serverPort, serverHost, (err) => {
  if (err) {
    console.error(err);
    client.close();
  } else {
    console.log('Message sent to server');
  }
});

client.on('message', (msg, rinfo) => {
  console.log(`Client received: ${msg} from ${rinfo.address}:${rinfo.port}`);
  client.close();
});

client.on('error', (err) => {
  console.log(`Client error: ${err.stack}`);
  client.close();
});