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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:56:25+00:00 2026-05-11T08:56:25+00:00

In C# to use a TcpClient or generally to connect to a socket how

  • 0

In C# to use a TcpClient or generally to connect to a socket how can I first check if a certain port is free on my machine?

more info: This is the code I use:

TcpClient c; //I want to check here if port is free. c = new TcpClient(ip, port); 
  • 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. 2026-05-11T08:56:26+00:00Added an answer on May 11, 2026 at 8:56 am

    Since you’re using a TcpClient, that means you’re checking open TCP ports. There are lots of good objects available in the System.Net.NetworkInformation namespace.

    Use the IPGlobalProperties object to get to an array of TcpConnectionInformation objects, which you can then interrogate about endpoint IP and port.


     int port = 456; //<--- This is your value  bool isAvailable = true;   // Evaluate current system tcp connections. This is the same information provided  // by the netstat command line application, just in .Net strongly-typed object  // form.  We will look through the list, and if our port we would like to use  // in our TcpClient is occupied, we will set isAvailable to false.  IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();  TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();   foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)  {    if (tcpi.LocalEndPoint.Port==port)    {      isAvailable = false;      break;    }  }   // At this point, if isAvailable is true, we can proceed accordingly. 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The file list returned from os.walk are not fully qualified… May 11, 2026 at 12:12 pm
  • added an answer If this is running on a server, a service seems… May 11, 2026 at 12:12 pm
  • added an answer We had the same problem, the only solution we found… May 11, 2026 at 12:12 pm

Related Questions

Let's say I'm creating a program in C that needs to use a tempfile.
I want to use a timer in my simple .NET application written in C#.
I have to use a class/assembly made in C# .NET from native C++ application.
You can use a standard dot notation or a method call in Objective-C to
I am trying to use a class from a C# assembly in vb.net. The
Is there a way to (ab)use the C preprocessor to emulate namespaces in C
I want to use Vectors in a C# application I'm writing, sepcifically a Vector3.
In my C# application, I use a regular expression to validate the basic format
I need to cut out and save/use part of a string in C#. I
I have c# that will run in a windows service. I'm trying to use

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.