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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:39:44+00:00 2026-06-18T11:39:44+00:00

I am debugging a c based linux socket program. As all the examples available

  • 0

I am debugging a c based linux socket program. As all the examples available in websites,
I applied the following structure:

sockfd= socket(AF_INET, SOCK_STREAM, 0);

connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));

send_bytes = send(sockfd, sock_buff, (size_t)buff_bytes, MSG_DONTWAIT);

I can detect the disconnection when the remove server closes its server program. But if I unplug the ethernet cable, the send function still return positive values rather than -1.

How can I check the network connection in a client program assuming that I can not change server side?

  • 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-18T11:39:45+00:00Added an answer on June 18, 2026 at 11:39 am

    But if I unplug the ethernet cable, the send function still return
    positive values rather than -1.

    First of all you should know send doesn’t actually send anything, it’s just a memory-copying function/system call. It copies data from your process to the kernel – sometime later the kernel will fetch that data and send it to the other side after packaging it in segments and packets. Therefore send can only return an error if:

    • The socket is invalid (for example bogus file descriptor)
    • The connection is clearly invalid, for example it hasn’t been established or has already been terminated in some way (FIN, RST, timeout – see below)
    • There’s no more room to copy the data

    The main point is that send doesn’t send anything and therefore its return code doesn’t tell you anything about data actually reaching the other side.

    Back to your question, when TCP sends data it expects a valid acknowledgement in a reasonable amount of time. If it doesn’t get one, it resends. How often does it resend ? Each TCP stack does things differently, but the norm is to use exponential backoffs. That is, first wait 1 second, then 2, then 4 and so on. On some stacks this process can take minutes.

    The main point is that in the case of an interruption TCP will declare a connection dead only after a seriously large period of silence (on Linux it does something like 15 retries – more than 5 minutes).

    One way to solve this is to implement some acknowledgement mechanism in your application. You could for example send a request to the server “reply within 5 seconds or I’ll declare this connection dead” and then recv with a timeout.

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

Sidebar

Related Questions

When debugging browser-based apps using Google Chrome's Developer Tools, is there a way to
I'd like to do some message debugging on traffic for a few protobuf based
I have one legacy web application based on struts2 (primarily using annotation). While debugging
Debugging a PHP program, is there any add-on/plug-in for browser which I can view
v8 has its own JSON based remote-debugging protocol and two UI debuggers:console application D8
When debugging my ASP.NET MVC (Razor-based) web site in IE10, I need to still
So usually when EXC_BAD_ACCESS happens when I'm debugging my (largely c++ based) iphone app,
The following page provides a nice simple solution for file based logging in Qt
Debugging a complex jQuery-based application that wasn't working in Opera browser, I traced back
For debugging purposes, I need to raise an application level message based on given

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.