Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

694
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!