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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:19:05+00:00 2026-06-17T15:19:05+00:00

I have a perl server side socket that returns fields one by one invoking

  • 0

I have a perl server side socket that returns fields one by one invoking send() on the client socket.

I have no issues in reading all the fields at the client side if the code is like below:

while ($response = <$sock>) {
print "$response";
last if $response eq "END_OF_REQUEST";
}

But if the client side code is like below, it’s going into a loop and is not working:

while(1) {      
$sock->recv($response, 1);
print "$response\n";    
last if $response eq "END_OF_REQUEST" ;
}

I agree that i can club all the fields and invoke only one send at the server side. But i am interested in knowing what’s wrong with the 2nd approach. Does changing the LENGTH arg of the recv in 2nd approach does the trick?

I kind of started getting hands-on directly without proper theoretical knowledge about sockets. Thanks for your patience.

  • 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-17T15:19:07+00:00Added an answer on June 17, 2026 at 3:19 pm

    The length argument to recv() is the maximum length of the message you want to receive, and recv() will never write more than that many characters into the buffer. (What happens to the rest of the message depends on the type of the socket; for streaming sockets it’ll be available for the next recv() call, while for datagram sockets it’s simply thrown away.)

    Thus, your $sock->recv($response, 1); will only write at most one character into $response. Obviously, a one-character string can never equal "END_OF_REQUEST".

    The simple solution is to pass a sufficiently large maximum length to recv(), so that your message will not be truncated.


    Here’s a simple demonstration:

    use strict;
    use warnings;
    use IO::Socket;
    
    my ($rd, $wr) = IO::Socket->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC)
        or die "socketpair: $!";
    defined $wr->send("Hello, world!") or die "send: $!";
    my $buf;
    do {
        defined $rd->recv($buf, 9) or die "recv: $!";
        print qq(received: "$buf"\n);
    } while ($buf !~ /!/);
    

    This will output:

    received: "Hello, wo"
    received: "rld!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a socket client in Perl. The server side is
I have a mission critical Perl-CGI server-side application that I need to extend or
I have a big issue with my java client. Server: perl, with IO::Socket; $n
I have a socket comminucation between Perl client and C++ server. Perl code: if
I have a Client-Server Perl program. I want to send a message stored in
I have written a perl script to send email using the gmail's smtp server:
I have some Apache Thrift (v.0.6.1) test application with perl-server and php-client. The behaviour
I am a perl developer that has never went into the client side programming
I have added in pg_hba.conf on the server side this line : host all
I have two Perl scripts that are supposed to do the following job: Server

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.