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

695
Visualizações
Node.js and Socket.io - how to send an array using the emit function

i'm using Node.js (Version 7.9.0) with socket.io(Version 1.7.3) and trying to send the arrays "softwareBez" and "softwareVersion" from the server to the client. Than the client should output the content of the array as text.

Here is my code:

---The server side---

var softwareBez = new Buffer(recTelegramm[2]);              // Create array with the length recTelegramm[2]
var softwareVersion = new Buffer(recTelegramm[3]);          // Create array with the length recTelegramm[3]

// Fill the array softwareBez
for(var i=0; i<recTelegramm[2]; i++)
{
    softwareBez[i] = recTelegramm[9+i];                     
}
//

// Fill the array softwareVersion 
for(var i=0; i<recTelegramm[3]; i++)
{
    softwareVersion[i] = recTelegramm[9+recTelegramm[2]+i]; 
}
//


    // Output for Tests
    console.log("softwareBez: ", softwareBez , "\n"); 
    console.log("softwareVersion: ", softwareVersion , "\n"); 

    // Send Data to Client
    io.sockets.emit('P_Sysinfo', {softwareBez: [softwareBez], softwareVersion: [softwareVersion]}); 

The output over console.log shows, that the arrays are filled correct.

---The client side---

$('#content').append
        (
            $('<li></li>').append($('<span>').text('Softwarebezeichnung: ' + data.softwareBez)),
            $('<li></li>').append($('<span>').text('Softwareversion: ' + data.softwareVersion))
        );

And the output in the Webbrowser is:

Softwarebezeichnung: [object ArrayBuffer]
Softwareversion [object ArrayBuffer]

So something seems to go wrong with the transmit of the arrays? Here I found something which I thought it was a solution: Are arrays allowed in the socket.io emit function? Therefore the "softwareBez: [softwareBez]" and "softwareVersion: [softwareVersion]" in the emit function (server side) is in the brackets "[" and "]". But with and without these brackets - the same problem....

Thanks for help

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Thanks a lot, this was the problem....

with the following on the server side it works:

var softwareBez = new Buffer(recTelegramm[2]);              // Create array with the length recTelegramm[2]
var softwareVersion = new Buffer(recTelegramm[3]);          // Create array with the length recTelegramm[3]

One more question: There are dec Numbers in the Array. Is there a simple possibility to convert these dec numbers into text over the ASCII-Table? Any given function or so?

over 4 years ago · Santiago Trujillo 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