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

  • Home
  • SEARCH
  • 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 6566257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:11:45+00:00 2026-05-25T14:11:45+00:00

I have a socket comminucation between Perl client and C++ server. Perl code: if

  • 0

I have a socket comminucation between Perl client and C++ server.

Perl code:

  if (!socket(SERVER, AF_INET, SOCK_STREAM, getprotobyname('tcp'))) {
    die "Can't allocate socket\n";
  } elsif (!connect(SERVER,sockaddr_in($PORT, $tcp_addr))) {
    die "Can't connect to server at $tcp_addr port $PORT...\n";
  }

  SERVER -> autoflush(1);

  print SERVER "$line";

If $line was too long, it is being fragmented, and on the C++ server side I have to call recv several times (without even knowing the actual expected length!).

What are the best ways to deal with it?

I thought of some ways:

  1. Maybe there is some Perl module that deals with it?
  2. Maybe I can just turn off fragmentation, but wouldn’t it cause more transmission fails?
  3. I can just add the message length to the sent message, and I will call recv until I receive the whole message, but isn’t it just ugly?
  4. Anything else?

What would the best solution be?

  • 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-25T14:11:45+00:00Added an answer on May 25, 2026 at 2:11 pm

    Add the message length as a 4byte header to the message. This is not ugly, but just as the “pros” do it. TCP/IP is a stream oriented protocol. You were just lucky that you got your messages in one recv call. It is possible to get any number of bytes, only half a message, one and a half message etc. as tcp/ip is transferring a continuous stream of bytes without any notion of packets at that level.

    The good side of this is that you can buffer your messages in userspace and can read as many bytes as you want into that buffer, and the process multiple messages out of this buffer isntead of repeatedly calling recv()

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

Sidebar

Related Questions

I have a class that encapsulates tcp socket communications with a server. For each
I want to open a TCP client socket in Python. Do I have to
I have a server that sends data via a socket, the data is a
I have a worker thread that is listening to a TCP socket for incoming
I have a server that listens for a connection on a socket: public class
I have recently written a socket server in PHP that will be handling communication
so - I have this Socket (not XMLSocket, just Socket) client. I also have
I have a Php application using stream_socket_client(), to get data through tcp from a
I have a c# application that runs as a windows service controlling socket connections
We have a simple project where we read data from a socket and we

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.