# FreeRTOS-TCP multiple interfaces.When I establish a TCP(Server or Client) connection, how should I specify which network card to use and which IP address to use

**URL:** <https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230>\
**Category:** Libraries\
**Created:** [February 21, 2024, 2:19pm UTC](https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230 "2024-02-21T14:19:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hane\_vv](https://avatars.discourse-cdn.com/v4/letter/h/e8c25b/32.png) [@hane\_vv](https://forums.freertos.org/u/hane_vv)\
**Post date:** [February 21, 2024, 2:19pm UTC](https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230/1 "2024-02-21T14:19:22Z")

</div>

I am using FreeRTOS-TCP multiple interfaces, with two network ports (one WAN port and one LAN port), one WIFI, and one 4G. When I establish a TCP(Server or Client) connection, how should I specify which network card to use and which IP address to use? I think I should use the “FreeRTOS\_bind” function, but specifically, the second parameter of “FreeRTOS\_bind” in the routine is NULL

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [February 21, 2024, 3:22pm UTC](https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230/2 "2024-02-21T15:22:13Z")

</div>

@hane_vv

Each of your network interfaces should have associated endpoints configured. During bind if when `pxAddress` is NULL then, based on the IP address of the target device you are trying to communicate with (server/client address), a matching endpoint (which belongs to any of the network interfaces) will be selected from the ARP/ND cache as part of the ARP/ND cache lookup of that IP. The endpoint in those caches will be based on the endpoint at which ARP/ND responses arrived. [FreeRTOS\_bind](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/bind.html) is used to bind a socket (either TCP or UDP) to a random local port number only when `pxAddress` is NULL.

If `pxAddress` while binding is configured to have the `sin_address.ulIP_IPv4` with the IP address of any of your endpoints of your interface of interest, then the socket will be configured with that endpoint.

---

<div class="post-metadata">

**Author:** ![Shub](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@Shub](https://forums.freertos.org/u/Shub)\
**Post date:** [February 23, 2024, 5:52am UTC](https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230/3 "2024-02-23T05:52:18Z")

</div>

@hane_vv

Agree with Tony.  
Just to add as a starting point you can configure the `pxAddress` to the IP address of the desired endpoint of your desired interface and rest will happen as per the flow.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 25, 2024, 6:36am UTC](https://forums.freertos.org/t/freertos-tcp-multiple-interfaces-when-i-establish-a-tcp-server-or-client-connection-how-should-i-specify-which-network-card-to-use-and-which-ip-address-to-use/19230/4 "2024-02-25T06:36:02Z")

</div>

A reply is on its way, I am working out a configuration that should make possible what you want to do.

I will first test it in real hardware.

Hein
