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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:40:16+00:00 2026-05-17T19:40:16+00:00

Any suggestions on testing a TCP client listener. What I’m looking for is actual

  • 0

Any suggestions on testing a TCP client listener. What I’m looking for is actual network stats like “payload size”, “time-out values”, “actual payload bytes received from server”.

  public static void tcpConnect()  { 
                int port = 12345;


                IPEndPoint ipep = new IPEndPoint(
                        IPAddress.Parse("xx.xx.xx.xx"), port);
                Socket server = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream, ProtocolType.Tcp);
                IPGlobalProperties _ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
                TcpConnectionInformation[] _tcpConnInfoArray = _ipGlobalProperties.GetActiveTcpConnections();

               // bool isAvaiable = true;

                try
                {
                    server.Connect(ipep);                   
                }   
                catch (SocketException e)
                {
                    Console.WriteLine("Unable to connect to server");
                    Console.WriteLine(e.ToString());
                    return;
                }
                NetworkStream ns = new NetworkStream(server);
                if (ns.CanRead)
                {
                    foreach (TcpConnectionInformation tcpConnInfo in _tcpConnInfoArray)
                    {
                        if (tcpConnInfo.LocalEndPoint.Port == port)
                        {
                            //isAvaiable = false;
                            Console.WriteLine("Error: Can't Read from Port");
                            break;
                        }

                        Console.Write("Local endpoint: {0} ", tcpConnInfo.LocalEndPoint.Address);
                        Console.Write("Remote endpoint: {0} ", tcpConnInfo.RemoteEndPoint.Address);
                        Console.Write("{0}", tcpConnInfo.State);
                    }
                }
                else 
                {
                    Console.WriteLine("Error: Can't Read from Socket");
                    ns.Close();
                    return;
                }
                while (true)
                {

                   string input = Console.ReadLine();
                    if (input == "exit")
                        break;
                    if (ns.CanWrite)
                    {
                        Console.WriteLine("NS Can write");
                        ns.Flush();

                    }
                }
                Console.WriteLine("Disconnection from server");
                ns.Close();
                server.Shutdown(SocketShutdown.Both);
                server.Close();


              }       

          }     
  • 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-05-17T19:40:17+00:00Added an answer on May 17, 2026 at 7:40 pm

    So if I read correctly the real aim is to monitor the connection to see if it is still alive? We all know TCP is a state-full protocol. This means the “socket” must remain open. So you client will have a socket which is open. The TcpClient is just a nice wrapper that give you the ability to read and write to the socket. From the MS API page we can see there is an Active property. As the documentation reads, this is not updated if the remote disconnects… this is too bad and perhaps the problem you have. However they give the advise that if you want to watch the socket you will see if the remote disconnects. You can do this using the Connected property.

    I know that not going to be the level of control you want, who wants to just see the TCP Client?? So get right at the Socket!!! once you have the socket you can have full control and viability over the connection. This should make you happy!!

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

Sidebar

Related Questions

I was curious whether anyone has any suggestions for performance testing libraries and frontends
I am looking for some kind of web regression testing tool. I would like
Has anyone got any suggestions for unit testing a Managed Application Add-In for Office?
Do you think that this is a good way for testing exceptions? Any suggestions?
Any suggestions on the best way to ensure thread safety when changing the properties
Any suggestions? Using visual studio in C#. Are there any specific tools to use
Any suggestions for good open source asp.net (C#) apps out there which meet as
Any suggestions on how to write repeatable unit tests for code that may be
Any suggestions on how to improve DataGridViewComboBoxColumn performace with large item sets? I've got
Any suggestions for an accurate Web Log analysis tool to generate reports on the

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.