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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:48:47+00:00 2026-05-30T00:48:47+00:00

I have been programming in C++ for a while but I am a beginner

  • 0

I have been programming in C++ for a while but I am a beginner to network programming and I am unclear on a couple of things so this is a three part question.

  1. In example applications, I have seen a call to send() on one socket, a check of its return value, and then immediately after, a call to recv() on the same socket. I find this confusing however as recv() is not called until after send() so is there not a risk that a reply message will arrive before recv is called? If so is this actually a problem or will the message just hang in limbo until recv is called and it is received?

  2. I wish to write a class which communicates with a server, and can make several different kinds of request to the server, with one function for each which sends a request then waits for a reply. My client will have an instance of this class as a member. Given that send() and recv() are blocking calls, even if I create a seperate thread for network communications how can I stop all network communications from being halted while waiting for a reply to one request? If one message fails then until send/recv times out I wont be able to make any more requests, so do I need more than one socket per client? More than one thread?

  3. I have been reading about thread safety, and given that send and recv are blocking calls I assume that my application will be threadsafe if I only have one thread per client for network communications, however if I do need more than one thread or more than one socket for each client (which I don’t know yet), how will I go about making it thread safe?

Sorry this was so long.
Thanks.

  • 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-30T00:48:49+00:00Added an answer on May 30, 2026 at 12:48 am
    1. The mechanism is not so simple. There may be buffers involved on the client side, on the server side or both. For example, a send on the client side may be considered completed when the message was copied to the buffer, not when it is actually sent down the wire. Similarly, messages will be copied to a buffer on the server-side, such that a send from the client matches a receive on the server. Don’t worry about this aspect.

    2. I would not advise you to do several sends from different threads on the same socket. It would probably be better to put the requests in a queue and have a single thread send them to the server. You can then wait for the reply on a separate thread if you wish.

    3. See number 2.

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

Sidebar

Related Questions

This is a super newbie question, I've been programming for a while, but am
Noob question. I have been programming at basic level for quite a while but
I'e been programming Java forever, but have been away from it for a while.
i've been programming for a while, but have never had a formal computer science
I've been programming in Java for a little while now but have never really
I'm quite new to objective c but have been programming for a while. I
I have been programming C for a while (but still pretty new to C)
I have been programming in Java for a while, but have never dealt with
I have been programming in PHP for a while but I still dont understand
I have a question about Java style. I've been programming Java for years, but

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.