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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:53:53+00:00 2026-05-22T15:53:53+00:00

i have a client which sends data to a server with 2 consecutive send

  • 0

i have a client which sends data to a server with 2 consecutive send calls:

send(_sockfd,msg,150,0);
send(_sockfd,msg,150,0);

and the server is receiving when the first send call was sent (let’s say i’m using select):

recv(_sockfd,buf,700,0);

note that the buffer i’m receiving is much bigger.

my question is: is there any chance that buf will contain both msgs? of do i need 2 recv() calls to get both msgs?

thank you!

  • 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-22T15:53:54+00:00Added an answer on May 22, 2026 at 3:53 pm

    TCP is a stream oriented protocol. Not message / record / chunk oriented. That is, all that is guaranteed is that if you send a stream, the bytes will get to the other side in the order you sent them. There is no provision made by RFC 793 or any other document about the number of segments / packets involved.

    This is in stark contrast with UDP. As @R.. correctly said, in UDP an entire message is sent in one operation (notice the change in terminology: message). Try to send a giant message (several times larger than the MTU) with TCP ? It’s okay, it will split it for you.

    When running on local networks or on localhost you will certainly notice that (generally) one send == one recv. Don’t assume that. There are factors that change it dramatically. Among these

    • Nagle
    • Underlying MTU
    • Memory usage (possibly)
    • Timers
    • Many others

    Of course, not having a correspondence between an a send and a recv is a nuisance and you can’t rely on UDP. That is one of the reasons for SCTP. SCTP is a really really interesting protocol and it is message-oriented.

    Back to TCP, this is a common nuisance. An equally common solution is this:

    • Establish that all packets begin with a fixed-length sequence (say 32 bytes)
    • These 32 bytes contain (possibly among other things) the size of the message that follows
    • When you read any amount of data from the socket, add the data to a buffer specific for that connection. When 32 bytes are reached, read the length you still need to read until you get the message.

    It is really important to notice how there are really no messages on the wire, only bytes. Once you understand it you will have made a giant leap towards writing network applications.

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

Sidebar

Related Questions

I have some simple questions, I have a client-server application and data sent on
I've got a strange problem. I have a client sending packets to my server,
I have a client-server game, where the client connects to a server and stays
I'm trying to find the best way to transfer data from server -> client
OK, so I have a socket InputStream over which the server is sending a
I have 2 processes running in different machines which are communicating via TCP sockets.
I have an API which which provides authentication via a signed response to a
I appologize for this lengthy post. I have made it as small as possible
We are designing a mobile application which reads barcodes of the products and get
I am having problems with making multithreaded Datagram Sockets for learning purposes in java.

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.