Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

696
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda