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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:09:49+00:00 2026-06-17T23:09:49+00:00

I am trying to implement the TCP SO_KEEPALIVE to close and reconnect my connection

  • 0

I am trying to implement the TCP SO_KEEPALIVE to close and reconnect my connection when a keep alive message does not receive a response. My problem is that I have not had any luck with this and I think (hope) it is because I am not implementing it right. Below is a example of how I am implementing this.

//var to re-set socket's timeout value
struct timeval timeout; 

//creates a variable for KEEPALIVE's optval parm
 int optval; 

//creates a variable for KEEPALIVE's optlen parm
   socklen_t optlen = sizeof(optval); 

// sets KEEPALIVE parms
optval = 1;
optlen = sizeof(optval);

// turns on KEEPALIVE property on socket
if (setsockopt (Socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0)
    {
        CloseSocket(Socket, 0);
        connect(Socket);

    }
  • 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-17T23:09:50+00:00Added an answer on June 17, 2026 at 11:09 pm

    Your code is only showing you setting the socket option then immediately closing and reopening it. Setting the socket option will not tell you that the keepalive has failed. You’ll get that as a result of checking the socket (with a read, write, poll/select etc.) Setting the option merely turns on the keep-alive sending & checking. Look for ETIMEDOUT as the errno.

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

Sidebar

Related Questions

I'm trying to implement a timeout for a Boost.Asio read on a TCP socket.
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
I am trying to implement a TCP server and using python script. So I
I am trying to implement a class that can listen for incoming TCP data.
I am trying to implement a (T)LV protocol over TCP sending protocol buffers from
I am trying to understand how I would implement message framing with WCF. The
After painstakingly trying to implement TCP file transfer in my conference chat application using
I am using a 3G UMTS connection. I am trying to implement HTTP tunneling
I have a wcf service running and I was trying to implement a tcp
I am trying to implement a TCP echo server and client program in Ubuntu

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.