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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:25:09+00:00 2026-06-11T09:25:09+00:00

I want my client application to connect to my server application, and continuously try

  • 0

I want my client application to connect to my server application, and continuously try to re-connect if the connection is ever lost.

I am currently trying to use a timer to check the connection every second by first attempting to send a packet with NetworkStream.Write and then checking TcpClient.Connected, but it doesn’t seem to be working. TcpClient.Connected never goes back to false after the client loses connection.

What would be the simplest way of doing this?

  • 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-11T09:25:10+00:00Added an answer on June 11, 2026 at 9:25 am

    If the connection is closed it should throw an exception. You can catch it and and re-open the connection. Here is an exception I got by shutting down a TcpListener while a TcpClient was connected.

    System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
    

    Edit:
    Here is a sample of how you could continuously re-try to connect. Note depending on your situation you may want to have a counter or timer so that it does not re-try forever.

    public class PersistantTcpClient
    {
        TcpClient Client { get; set }
    
        public void Start()
        {
            while (true)
            {
                 try
                 {
                    this.Client.Connect("host", port)
    
                    // once it can connect, get back to work!
                    DoWork();
                 }
                 catch (SocketException)
                 {
                    // if it cannot connect, keep trying
                 }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to install my client an application that uses SQL Server 2008 database.
I want to build a basic Client-Server application, where my android smartphone can stream
I have a client - server application, where I want to add a exception
I am developing a client-server application using .Net Remoting. From my server I want
I am going to make a client-server application using Node.js, and I want to
I am testing one Desktop based client server application. I want to perform a
I am developing an client server communication application in C. I want to encrypt
I want to develop a client-server based desktop application using .Net 4, C# and
In my java application I want to transfer some Images from client to server.
I have a .NET application that I want to use as a client to

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.