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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:29:06+00:00 2026-06-07T16:29:06+00:00

I thought I would start a new question for this. I have a TCP

  • 0

I thought I would start a new question for this.
I have a TCP server/client set up and they communicate the way I generally want. 1 server and 1 client.

What I want to do now is add functionality that would allow the client to automatically reconnect to the server once a connection is lost. I’m having trouble finding complete information online on how to do this. This is (hopefully) the relevant problem code:

SERVER:

    case FD_ACCEPT: //Connection request  
    {  
        SOCKET TempSock = accept(s, (struct sockaddr*)&fromm, &fromlenn);  
        s = TempSock; //Switch old socket to the new one  
        m_sNetworkStatus.Format("[%s] accepted.", inet_ntoa(fromm.sin_addr));  
        m_hNetworkStatus.SetWindowTextA(m_sNetworkStatus);  
    }  

The first client connection goes through fine. The server listens, the client connects, the client disconnects…
BUT the second time the client tries to connect the resultant client IP address (as seen by the server) is such that printing inet_ntoa(fromm.sin_addr)) will output [0,0,0,0]. So, the client ‘thinks’ it’s connected but it is not and the server prints that it accepted the connection but no data can be sent…disconnecting on the client side and attempting to reconnect again leads to a

connection refused 10061 error.

(If I disconnect from the server side and listen to a new port there’s no problem)

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-06-07T16:29:08+00:00Added an answer on June 7, 2026 at 4:29 pm

    You are overwriting your listening server socket s with the result of the accept(), i.e. the connected socket. This is totally wrong – you are supposed to reuse that same server socket you called listen() on for all subsequent calls to accept(), which will give you a new socket every time each representing full new TCP connection from a client.

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

Sidebar

Related Questions

I'm very new to web app development and I thought I would start with
this post is off the back of my last question (thought i'd start a
This is what I thought would be a simple select clause, however the following
I'm new to iPhone development, so my apologies if this is a ridiculous question.
I have asked a similar question before here , but after much thought, and
UPDATE 3: This happens when I have saved the vb6 script, close word, start
I'm planning to use Netty to design a TCP Server. When the client connects,
I will preface this question with the fact that I am extremely new to
[I have posted this question earlier in the PowerShell Technet forum, but without a
To elaborate on my question, the particular situation is this: If I have a

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.