const net = require('net'); const fs = require('fs'); const server = net.createServer(); const port = 9000; // server.on('connection', handleConnection); // server.listen(port, function() { // console.log('server listening to %j', server.address()); // }); // // function handleConnection(conn) { // conn.setEncoding('utf8'); // var remoteAddress = conn.remoteAddress + ':' + conn.remotePort; // console.log('new client connection from %s', remoteAddress); // // conn.on('data', onConnData); // conn.once('close', onConnClose); // conn.on('error', onConnError); // // function onConnData(d) { // console.log('connection data from %s: %j', remoteAddress, d); // var msg = 'connection data from '+ remoteAddress +' : ' + d; // hex.toString() // //conn.write(d); // fs.appendFile('message.txt', msg, function (err) { // if (err) throw err; // console.log('Saved!'); // }); // // } // // function onConnClose() { // console.log('connection from %s closed', remoteAddress); // } // // function onConnError(err) { // console.log('Connection %s error: %s', remoteAddress, err.message); // } // } function stringToHex(arr) { let buffer = Buffer.from(arr); console.log(buffer.toString('hex')); let hexaa = Buffer.from(buffer.toString('utf-8')); console.log('ascii --> '+ hexaa.toString('ascii')); // let bufStr = Buffer.from(arr, "utf-8"); // // // for (const b of bufStr) { // let bufStr = Buffer.from(b.toString(), 'utf-8'); // //let hexa = bufStr.toString('ascii'); // console.log(bufStr.toString('hex')); // //console.log(bufStr.toString('hex')) // } // for(i = 0; i< arr.length; i++){ // console.log(arr[i]); // let bufStr = Buffer.from(arr[i]); // console.log(bufStr.toString('hex')) // } //converting string into buffer // let bufStr = Buffer.from(str, 'ascii'); //let bufStr = Buffer.from(str, 'utf8'); //with buffer, you can convert it into hex with following code // console.log(bufStr.toString('hex')); //console.log(bufStr.toString('ascii')); } //stringToHex('\u0013D\u0006d\u0000\u0001\u0000\u0006'); stringToHex([120,120,60,34,1,3,89,81,0,133,22,9,85,22,2,17,22,5,0,22,2,17,22,5,1,198,3,14,11,49,5,65,133,212,0,56,210,9,2,212,6,11,232,0,195,132,70,7,217,41,100,0,2,0,38,252,0,45,74,0,9,167,44,13,10]); //{"type":"Buffer","data":[120,120,60,34,1,3,89,81,0,133,22,9,85,22,2,17,22,5,0,22,2,17,22,5,1,198,3,14,11,49,5,65,133,212,0,56,210,9,2,212,6,11,232,0,195,132,70,7,217,41,100,0,2,0,38,252,0,45,74,0,9,167,44,13,10]