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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:09:02+00:00 2026-06-14T20:09:02+00:00

This server works fine but if I do this bash$ (echo -n abcd ;sleep

  • 0

This server works fine but if I do this

bash$ (echo -n “abcd” ;sleep 50 ; echo “efgh”) | nc localhost 9090

The server blocks for 50 seconds.In my complete code I have more than one IO::Select::INET. I have another socket listen other port (1234), and I can’t process anything in that port while the server is blocking by the sleep. I try change the getline by getc but I only read the first letter “a” and it blocks.

Someone can help me?

use common::sense;
use IO::Select;
use IO::Socket;

use constant PORT1 => 9090;
use constant TIMEOUT => 1;

my $event_socket  = new IO::Socket::INET(Listen => 1, LocalPort => PORT1, ReuseAddr => 1) 
    or die "Can't bind event_socket: $@\n";

my $sel = IO::Select->new;
$sel->add($event_socket);

my $event_emiter = undef;

while(1){ 
    foreach my $sock (my @ready = $sel->can_read(TIMEOUT)) {
        if ($sock == $event_socket) {
            my $new = $event_socket->accept;
            binmode($new, ":encoding(UTF-8)");
            $sel->add($new);

            $event_emiter=$new;

            warn "[event socket] connect from ",$new->peerhost, "\n";
        } elsif ($sock == $event_emiter) {
            unless($sock->eof){
                my $recv_data = $sock->getline;
                warn "[event socket] LOL '$recv_data'\n";
            } else {
                $sel->remove($sock);
                $sock->close;
                $event_emiter = undef;
                warn "[socket] disconnect\n";
            }
        } else {

            $sel->remove($sock);
            $sock->close;

            warn "[socket] disconnect\n";
        }
    }   
}
  • 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-14T20:09:03+00:00Added an answer on June 14, 2026 at 8:09 pm

    Rather than reading available data, you’re reading until you read a newline. Always use sysread.

    Change

        elsif ($sock == $event_emiter) {
            unless($sock->eof){
                my $recv_data = $sock->getline;
                warn "[event socket] LOL '$recv_data'\n";
            } else {
                $sel->remove($sock);
                $sock->close;
                $event_emiter = undef;
                warn "[socket] disconnect\n";
            }
        }
    

    to

        elsif ($sock == $event_emiter) {
            our $buf; local *buf = \$bufs{$fh};  # alias $buf = $bufs{$fh};
    
            my $rv = sysread($fh, $buf, 64*1024, length($buf));
            if (!$rv) {
                if (defined($rv)) {  # EOF
                    # ... Handle anything left in $buf ...
                } else {  # Error
                    # ... Handle error ...
                }
    
                delete $bufs{$fh};
                $sel->remove($sock);
                $sock->close;
                $event_emiter = undef;
                warn "[socket] disconnect\n";
                next;
            }
    
            while ($buf =~ s/^(.*)\n//) {
                warn "[event socket] LOL '$1'\n";
            }
        }
    

    And add my %bufs; outside the select loop.

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

Sidebar

Related Questions

This works perfectly fine on localhost but doesn't work on my server, could anyone
My Apache server works fine without -DSSL, but does not start with SSL. This
PHP curl at our localhost works fine but not on any other server Here
We have a ubuntu test server that this simple script works fine on where
The code below is creating a server to communicate with clients.This code works fine
I want to port this SQL query, which works just fine on SQL Server,
I run this in localhost and it works. In the server the PHP script
I'm trying to dump a database from another server (this works fine), then restore
I have used a Asynchronous TCP/IP server, everything works fine but when a client
when i try access my webapplication with link http://localhost:8080/MyWebApp/login.do It works fine but when

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.