Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
how to convert binary to string (big endian) format

ı have a tcp socket and ı try to get binary data from there and convert it to string by node js

here is my code

const Net = require('net');
const port = 4000;
const host = '0.0.0.0';

const client = new Net.Socket();
client.connect({ port: port, host: host }), function() {
    console.log('TCP connection established with the server.');

    client.write('Hello, server.');
};
client.on('data', function(chunk) {
    console.log(chunk);
    
    client.end();
});

client.on('end', function() {
    console.log('Requested an end to the TCP connection');
}); 

and the output is

<Buffer 82 44 53 53 76 57 37 56 4c 6d 62 ed 14 00 00 00 00 00 00 00 00 00 00 00 00 4c 05 e5 58 00 00 00 00 e1 8f 80>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you just missing to set encoding. I think all you need to do is to client.setEncoding("utf8") after you declare it, and it should work. If not, then you should check out a Buffer api and play with transforming your binary data into different formats.

Here's the useful references:

https://nodejs.org/api/net.html#event-data

https://nodejs.org/api/net.html#socketsetencodingencoding

https://nodejs.org/api/buffer.html

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda