CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Socket binding with routing table

  1. #1
    Join Date
    Oct 2009

    Socket binding with routing table

    I'm writing a server application which sends streams to clients at high throughputs.
    Since one network adapter is not enough for all streams, I would like to take advantage of all network adapter available.
    The application performs some kind of load balancing by binding socket to specific network adapters according to some load balancing algorithm.

    I'm using Socket.Bind in order to determine from which adapter to send the data from.

    I'm encountering a problem which I could not get an answer anywhere, maybe one of you guys could help me.

    I have two network adapters: and
    For example, the application would like to send the stream from

    1. The application performs socket.Bind( and the stream is sent from this socket.
    2. By looking at perfmon I notice that the data is actually sent from
    3. After few hours of knocking my head to the wall I found that has a lower routing metric, therefore, the OS decides to sent the data from

    I have two questions please:
    1. Is there any way to bypass the routing table, I mean something like ForceBind or something like that?
    2. In case there is no way to do (1), in case all network adapters have the same routing metric, can I be sure that Socket.Bind will result in sending the data from where I actually meant?

    Thanks a lot.

  2. #2
    Join Date
    Nov 2002

    Re: Socket binding with routing table

    On Windows, a call to bind() affects card selection only incoming traffic, not outgoing traffic.

    Thus, on a client running in a multi-homed system (i.e., more than one interface card), it's the network stack that selects the card to use, and it makes its selection based solely on the destination IP, which in turn is based on the routing table. A call to bind() will not affect the choice of the card in any way.

    It's got something to do with something called a "Weak End System" ("Weak E/S") model. Vista changed to a strong E/S model, so the issue might not arise under Vista. But all prior versions of Windows used the weak E/S model.

    With a weak E/S model, it's the routing table that decides which card is used for outgoing traffic in a multihomed system.

    See if these threads offer some insight:

    "Local socket binding on multihomed host in Windows XP does not work" at http://www.codeguru.com/forum/showthread.php?t=452337

    "How to connect a port to a specified Networkcard?" at http://www.codeguru.com/forum/showthread.php?t=451117. This thread mentions the CreateIpForwardEntry() function, which (I think) can be used to create an entry in the routing table so that all outgoing IP traffic with a specified server is routed via a specified adapter.

    "Working with 2 Ethernet cards" at http://www.codeguru.com/forum/showthread.php?t=448863

    "Strange bind behavior on multihomed system" at http://www.codeguru.com/forum/showthread.php?t=452368


  3. #3
    Join Date
    Nov 2002

    Re: Socket binding with routing table

    Incidentally, "weak end system" is sometimes called "weak host model" or "weak host behavior". See:

    "Strong and Weak Host Models" at http://technet.microsoft.com/en-us/m....cableguy.aspx

    "Next Generation TCP/IP Stack in Windows Vista and Windows Server 2008" at http://technet.microsoft.com/en-us/l.../bb878108.aspx (which discusses the change in Vista from weak to strong)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)