title: How to implement instantiation of TcpClient, IPEndPoint , IPAddress objects instantiating for both cases IPv4 and IPv6 address when passed As Strings
body: <p>For my .NET C# application, we have  modules that are need to communicate via the TCP/IP protocol.</p>
  
  <p>I decided to use Microsoft's System.Net.Sockets API</p>
  
  <p>The modules that are represented by the "TcpListener" class could be either be </p>
  
  <p>-IPv4 address based
  -IPv6 address based</p>
  
  <p>The problem is that the modules that use the "TcpClient" class need to instantiate the "TcpClient" in such a way that it is intelligent to take either IPv4 or IPv6 address (that initially gets passed as a string)</p>
  
  <p>To elaborate, the module that uses "TcpClient" class could have a constructor like the following:</p>
  
  <pre><code>public ClientModule(string ipV4OrIpV6Address, int portNumber){
  ………………………
  …………..
  ……….
  }
  </code></pre>
  
  <p>When I reviewed Microsoft's documentation ( <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.-ctor?view=netframework-4.8#System_Net_Sockets_TcpClient__ctor_System_Net_IPEndPoint_" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.-ctor?view=netframework-4.8#System_Net_Sockets_TcpClient__ctor_System_Net_IPEndPoint_</a> ) , I found the following TcpClient constructor:</p>
  
  <blockquote>
    <p>TcpClient(IPEndPoint)</p>
    
    <p>Initializes a new instance of the TcpClient class and binds it to the
    specified local endpoint.</p>
  </blockquote>
  
  <p>Furthermore, I tried to search more about instantiating the IPEndPoint class, and I came across ( <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.ipendpoint.-ctor?view=netframework-4.8#System_Net_IPEndPoint__ctor_System_Net_IPAddress_System_Int32_" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/system.net.ipendpoint.-ctor?view=netframework-4.8#System_Net_IPEndPoint__ctor_System_Net_IPAddress_System_Int32_</a> )</p>
  
  <p>Each of the modules will be on different physical computer servers.</p>
  
  <p>How do I go about instantiating the Microsoft's IPAddress object in such a way that it will be intelligent enough to handle both IPv4 and IPv6 address As Strings regardless of which one gets passed as an argument?</p>