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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:26:48+00:00 2026-06-12T18:26:48+00:00

A valid socket connection is already established to a server. There’s a simple loop

  • 0

A valid socket connection is already established to a server. There’s a simple loop designed to continue receiving data until the server stops sending any more. All the documentation indicates that trying recv() too many times should just cause it to return 0 or -1 (depending on the situation). Instead it’s killing the thread with some sort of IOError (at the line with the recv call). What am I missing?

Edit: sad is just some stringstream. I promise it has nothing to do with the problem 😀

Another Edit: included errno.h and checked for errno codes, to no avail.

do {            
    memset(buffer,0,sizeof(buffer));
    bytes = recv(s,buffer,sizeof(buffer)-40,0);
    sad << buffer;
    Sleep(1);
} while (bytes>0);
  • 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-12T18:26:49+00:00Added an answer on June 12, 2026 at 6:26 pm

    Perhaps you should also check errno, since there might be a permature end to the communication channel.

    #include <errno.h>
    #include <string.h>
    
    do {            
        memset(buffer,0,sizeof(buffer));
        bytes = recv(s,buffer,sizeof(buffer)-40,0);
        if (errno)
           break;
        sad << buffer;
        Sleep(1);
    } while (bytes>0);
    
    if (errno)
       std::cerr << "Premature end of connection: " << strerror(errno) << '\n';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a socket server that is supposed to receive UTF-8 valid characters from
I have: A delegate to handle a socket connection that reads and writes data
Considers me@there valid. Is not a TLD required? try { foreach (var email in
i have a simple server that accepts clients. The client connect to the server.
How can I avoid, to send data via CFSocketSendData to an invalid socket? I've
I am sending Push notification from PHP to iPhone. Connection was established successfully but
I am testing out a Socket Server application in c and I am getting
I am trying to send Binary data using python raw socket. For that i
I'm using the ws module in nodejs for a web socket server, and the
I am using the server-client model for communicating with a hardware board using socket

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.