Set Local IPEndPoint and ExclusiveAddressUse RRS feed

  • Question

  • I have a server with multiple nics.  I need to specify what LOCAL NIC I want to use.  The only way I can see to do this is to

    IPAddress ip = IPAddress.Parse(""); 
    IPEndPoint ep = new System.Net.IPEndPoint(ip, 240);
    tcpc = new TcpClient(ep);

    I want to set the ExclusiveAddressUse = false.

    Unfortunately when you do this you can't set ExclusiveAddressUse because this property must be set before Bind is called.  The socket must not be bound or connected.

    It seems the only way to set the localendpoint is when you instantiate the tcpc client.  Once the tcpc client is created you can't set  ExclusiveAddressUse


    This property must be set before the underlying socket is bound to a client port. If you call Connect, BeginConnect, TcpClient(IPEndPoint), or TcpClient(String, Int32), the client port is bound as a side effect of the method, and you cannot subsequently set the ExclusiveAddressUse property

    • Edited by chuck02323 Tuesday, April 14, 2015 8:28 PM
    Tuesday, April 14, 2015 7:33 PM

All replies

  • For instance if you have:

    var endPoint = new IPEndPoint(IPAddress.IPv6Any, 800);
    using (var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
        socket.AcceptAsync(new SocketAsyncEventArgs().Completed += ...);

    you'll start listening for all incoming connections from all IPv6 addresses on port 800. Now if you create another socket with an exact IP on the same port, the new socket will take precedence and start listening for that exact IP on port 800. This is useful for smaller set of scenarios (i.e. for a transient connection where you read/write to an exact IP using a secure channel).

    Wednesday, April 15, 2015 4:41 AM
  • Not quite my scenario.  I would like the connection to be shared.  In your scenario while you did use a using statement to close the socket.  The Tcp standard puts the socket in a Time_wait for 6 minutes, this could prevent reuse of the socket during that period.  That's why I need to set ExclusiveAddressUse to false.

    Wednesday, April 15, 2015 1:13 PM
  • I did a network trace.

    I found that in the c# code I do a send.

    15 seconds later it shows up in the NetMonitor trace as sent.

    I disable Symantec Endpoint Protection, no change.

    Thursday, April 30, 2015 8:40 PM