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 6077597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:20+00:00 2026-05-23T10:44:20+00:00

For some reason when I send a message to the port and attempt to

  • 0

For some reason when I send a message to the port and attempt to read it in via a buffer, it always hangs as socket.on('end') never seems to be reached. Any ideas?

var net = require('net');
var buffer = [];

var server = net.createServer(function(socket) {

    socket.on('data', function(data) {
        buffer.push(data);
    });

    socket.on('end', function() {
        try {
            var data = buffer.join("");
            console.log(data);
            socket.end('ok');

        } catch (e) {
            console.log('Error: ' + e.message);
            return;
        }
    });
});

server.listen(3000, '127.0.0.1');

*Edit: here is the PHP that sends the command…

public function sendDaemonCommand($address, $template_id, $params = array()) {

    $port = 3000;
    $command = array('template_id' => $template_id, 'params' => $params);
    $command = json_encode($command);

    // Create a TCP Stream socket
    if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
        $this->logError("Failed to create socket on " . $address . "\n\n" . socket_strerror(socket_last_error()) . "\n\nCommand:\n\n" . $command . "\n" . $this->functionTraceback());
        return false;
    }

    // Connect to socket
    if (socket_connect($sock, $address, $port) === false) {
        $this->logError("Failed to connect to socket on " . $address . "\n\n" . socket_strerror(socket_last_error($sock)) . "\n\nCommand:\n\n" . $command. "\n" . $this->functionTraceback());
        socket_close($sock);
        return false;
    }

    // Write command to socket
    if (socket_write($sock, $command) === false) {
        $this->logError("Failed to write command to socket on " . $address . "\n\n" . socket_strerror(socket_last_error($sock)) . "\n\nCommand:\n\n" . $command. "\n" . $this->functionTraceback());
        socket_close($sock);
        return false;
    }

    // Read back from socket
    if (($out = socket_read($sock, 1024)) !== false) {
        $out = trim($out);
        if ($out == "") {
            $this->logError("No message received back from socket on " . $address . "\n\n" . socket_strerror(socket_last_error($sock)) . "\n\nCommand:\n\n" . $command. "\n" . $this->functionTraceback());
            socket_close($sock);
            return false;
        }
    }
    else {
        $this->logError("Failed to read from socket on " . $address . "\n\n" . socket_strerror(socket_last_error($sock)) . "\n\nCommand:\n\n" . $command. "\n" . $this->functionTraceback());
        socket_close($sock);
        return false;
    }

    socket_close($sock);
    return $out;
}
  • 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-05-23T10:44:20+00:00Added an answer on May 23, 2026 at 10:44 am

    Set allowHalfOpen to true in net.createServer then use socket_shutdown($sock, 1) after write and socket_shutdown($sock, 0) after read.

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

Sidebar

Related Questions

I'm using CFMAIL to send out an email. For some reason, when I edit
For some reason I never see this done. Is there a reason why not?
For some reason when I attempt to make a request to an Ajax.net web
I can make smtplib send to other email addresses, but for some reason it
For some reason my bot wont private message a % of people on the
I'm trying to send mails using PHP. For some reason when I receive the
For some reason when I create a new namespace in Visual Studio 2008 its
For some reason, when I try to install SQL Server 2008 Express , I
For some reason, lately the *.UDL files on many of my client systems are
For some reason, Section 1 works but Section 2 does not. When run in

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.