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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:51:59+00:00 2026-06-06T09:51:59+00:00

Background : my application has the option to check automatically whether a device on

  • 0

Background : my application has the option to check automatically whether a device on the network is connected to the network.

If a device is not connected, it is represented as a blue square, and a green square for connected. I’ve tested the program rather thoroughly and have a few different sets of data to look at;

If a device starts off disconnected, i can connect, and then disconnect, which goes from blue, to green, to blue, but stops functioning after this.

If a device starts of connected, i can disconnect, but then not connect again, so this goes from green, to blue, but then stops functioning.

Here are some snippets of code to show how i’m connecting to these (this is not asynchronous as some devices to not have callbacks(?));

TcpClient _tc = new TcpClient();
if (!_tc.Client.Connected)
            {
                try
                {
                    _tc.Client.Connect(device.deviceIPAddress, device.devicePort);
                    _tc.Client.ReceiveTimeout = 10;
                }
                catch
                {
                    if (deviceDownNotified == false)
                    {

                        //do stuff to notify me

                    }
                }

            }


            if (_tc.Client.Connected)
                {
                  tcpSet = true;
                    try
                    {
                        result = this.SendCommandResult(bData, 72);

                        if (result[0] == 0xF0 && result[1] == 0xF0 && result[2] == 0x00 && result[3] == 0x02 && result[68] == 0xF0 && result[69] == 0xF0)
                        {

                            CheckChanges(result, device, exit);
                            deviceDownNotified = false;

                        }
                    }
                    catch
                    {

                    }


                 }

edit: also i was just thinking, theres not really any need for me to disconnect manually sometimes. if a client isn’t connected, then connect, if it is, then do stuff. i’m a bit baffled as to which it switches between states once and stops working though.

I think my issue may be due to the way i am disconnecting the socket / client if the device is disconnected. Anyone have any ideas? if you need more information, just ask.

edit 2: i wired up a reconnect button that i clicked manually when it should reconnect and i get the following error exception:

“Once the socket has been disconnected, you can only reconnect again asynchronously, and only to a different EndPoint. BeginConnect must be called on a thread that won’t exit until the operation has been completed.”

  • 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-06T09:52:00+00:00Added an answer on June 6, 2026 at 9:52 am

    fixed my own problem. finally. Here’s some information for anyone out there reading this that may be looking for a solution.

    from what i gather, when a TCP connection is interrupted, you must create a new one as it’s not possible to reconnect or reuse in this way. what i did was this:

    (modified from code in my question)

    if (!_tc.Connected)
                {
                    try
                    {
    
    
                        connect2(deviceIPAddress, devicePort);
    
                    }
                    catch
                    {
                        if (deviceDownNotified == false)
                        {
    
                            ((ListBox)mainUI.Controls["lbLog"]).InvokeEx(f => ((ListBox)mainUI.Controls["lbLog"]).Items.Add("device " + device.deviceDescription + " down at " + System.DateTime.Now));
                            (mainUI.Controls["btn" + device.deviceButtonNumber]).BackgroundImage = null;
                            (mainUI.Controls["btn" + device.deviceButtonNumber]).BackColor = Color.Blue;
                            deviceDownNotified = true;
                            try
                            {
    
                                _tc = new TcpClient();
    
                                initialPoll = false;
    
    
                                MessageBox.Show("here");
                            }
                            catch (Exception error)
                            {
                                MessageBox.Show(error.Message);
                            }
                        }
                    }
    
                }
    

    Here i simply created a new tcplistener with the same name (my original one was a variable of an instance of a class (what a tongue twister). creating this new TCP instance and then setting my inialPoll variable allowed everything to get back into track.

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

Sidebar

Related Questions

In my application user has an option to change his background by choosing an
My application has many classes, worker threads, and background service operations. Notifications can come
My application has 2 views, and I want to play a background sound only
My Rails application has a number of tasks which are offloaded into background processes,
During my application setup, the user has the option of installing a new SQL
I’m wanting to create a iPhone application where the user has the option to
I am developing a WPF application, where user has the option to navigate between
One of my applications has property of images as background of Cells in UITableView,
Bckground I have a networked application written in C#. my server program has a
I am from Java Desktop Application background. May I know what is the best

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.