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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:49:29+00:00 2026-05-11T20:49:29+00:00

I have a C++ app that uses standard socket calls and I want to

  • 0

I have a C++ app that uses standard socket calls and I want to know if I can tell if a socket is still open without sending or receiving any data. Is there a reliable select or ioctlsocket call I can make?

  • 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-11T20:49:30+00:00Added an answer on May 11, 2026 at 8:49 pm

    If you try to recieve one byte, you can receieve several errors, if you were to have a non-blocking socket, and try to receieve on a valid connection, you will get the error WSAEWOULDBLOCK.

    Knowing this we can check a non blocking socket like so

    bool connected(SOCKET sock)
    {
         char buf;
         int err = recv(sock, &buf, 1, MSG_PEEK);
         if(err == SOCKET_ERROR)
         {
              if(WSAGetLastError() != WSAEWOULDBLOCK)
              {return false;}
         }
         return true;
    }
    

    as you can see from the return value of recv recv may return a timeout or several other errors for disconnect, i belive WSAEWOULDBLOCK is the only value it may return if there was an error but still connected, but you may want to double check that list of return values. Also the flag used in recv (MSG_PEEK) means that the data is still read-able when you go to look later after the check, so you don’t need to worry about losing one byte of data.

    I believe this will only work well with non-blocking sockets, as it may block until it receives data. If you want to use blocking socket you may want to set it non-block with ioctlsocket before this check, then return it to how it was.

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

Sidebar

Related Questions

I have a standard php app that uses SQL Server as the back-end database.
I am distributing an app that uses the Python/C API. I have all standard
I have a standard Rails app that uses a database, sqlite3 and the webrick
I have a fairly standard star voting functionality in my app that uses jQuery's
I have an iPhone app (in XCode 4) that uses the standard Tab Bar
I have an app that uses standard id integer autoincrement values. I also have
I have an app that uses EF. To test my stuff I generally wrap
I have an app that uses the python/c api and I was wondering what
I have an app that uses a tableview, along with a UIButton that I
I have a App that uses the In App feature. -(void) completeTransaction: (skPaymenttransaction *)transaction{

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.