Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:26:56+00:00 2026-06-14T11:26:56+00:00

I have a very simple TCP socket in Node.js. It connects to a device

  • 0

I have a very simple TCP socket in Node.js. It connects to a device that sends data back in XML format. There is a C# program that does this same trick, but I had to build it in Node.js.

So, when the device sends a message, I’m getting the response about 5 seconds later! Where the C# program gets it 1 or 2 seconds later.

It looks like the ‘tcp socket’ has a specific polling frequency or some kind of ‘wait function’. Is that even possible? Everytime an incoming message displays. It also display’s the exit message of “sock.on(‘close’)”

It seems that after 5 seconds the ‘server’ automaticly closes. See bottom lines “console.log(‘[LISTENER] Connection paused.’);” After that, the incoming message gets displayed correctly.

What is wrong with my code?

// Set Node.js dependencies
var fs = require('fs');
var net = require('net');

// Handle uncaughtExceptions
process.on('uncaughtException', function (err) {
    console.log('Error: ', err);
    // Write to logfile
    var log = fs.createWriteStream('error.log', {'flags': 'a'});
    log.write(err+'\n\r');

});

/*  
    -------------------------------------------------
    Socket TCP : TELLER
    -------------------------------------------------
*/
var oHOST = '10.180.2.210';
var oPORT = 4100;

var client = new net.Socket();
client.connect(oPORT, oHOST, function() {

            console.log('TCP TELLER tells to: ' + oHOST + ':' + oPORT);

            // send xml message here, this goes correct!
            client.write(oMessage);                     
});

// Event handler: incoming data
client.on('data', function(data) {
    // Close the client socket completely
    client.destroy();
});

// Event handler: close connection
client.on('close', function() {
    console.log('[TELLER] Connection paused.');
});     

/*  
    -------------------------------------------------
    Socket TCP : LISTENER
    -------------------------------------------------
*/
var iHOST = '0.0.0.0';
var iPORT = 4102;

// Create a server instance, and chain the listen function to it
var server = net.createServer(function(sock) {

    // We have a connection - a socket object is assigned to the connection automatically
    console.log('TCP LISTENER hearing on: ' + sock.remoteAddress +':'+ sock.remotePort);

    // Event handler: incoming data
    sock.on('data', function(data) {
        console.log('Message: ', ' '+data);
    });

    // Event handler: close connection
    sock.on('close', function(data) {
        console.log('[LISTENER] Connection paused.');
    });

}).listen(iPORT, iHOST);    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:26:58+00:00Added an answer on June 14, 2026 at 11:26 am

    So within the “TELLER” I had to write “sock.write(data);” inside the “sock.on(‘data’, function(data)” event.

    It works now. Thanks Jeremy and rdrey for helping me in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple XML in a string that I'm trying to load via
I have a very simple Winsock2 TCP client - full listing below - which
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have written a very simple socket server. It listens in post 63254. First
I have a very simple php ldap script that is only failing when running
I'm trying to set up a very simple UDP socket server with python that
I am trying to adapt my simple socket server so that it can have
I have a sample service to test WCF net.tcp communication. It is very simple
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have a worker thread that is listening to a TCP socket for incoming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.