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

255
Views
No value returning from callback - Nodejs, Javascript

I am sending strings from Matlab to Nodejs via TCPIP, where Matlab creates a local server and Nodejs acts as the client. Up to this point, everything works out just fine.

Now I want to perform a command if a specific string was sent. However, it seems as if the string, that is beeing received, is not assigned to the variable I am using for the codition for the if-statement. Find the code of the Nodejs-side below

client = require('./client');
host='localhost';
port=5000;
c = new client(host, port);

var message = c.receive();
if (message == "ping") {
    console.log("received ping");
};

Code for the client object

net = require('net');

function Client(host, port){
this.queue = [];
this.socket = new net.Socket();
this.socket.connect(port, host, function() {
    console.log('Connected');
});
this.queue = [];
}

Client.prototype.send = function (data){
this.socket.write(data+'\n');
}

Client.prototype.receive = function (){
var that = this;
this.socket.on('data', function(data) {
    that.queue.push(data);
    console.log(''+data);
});
}

Client.prototype.disconnect = function (){
this.socket.on('close', function() {
    console.log('Connection closed');
    this.socket.destroy();
});
}

module.exports = Client;

Is there any mistake in the first code block or do i need to modify "receive" in client? Thanks for any advice.

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