A short comment at the end of this long topic:
Within FreeRTOS+TCP, a port number can only be bound to one socket system wide. So for instance, you can open one HTTP socket at port 80, which will receive connections from all endpoints and all interfaces. And you can only bind one UDP socket to port 17000.
This behaviour has been present in all earlier versions of +TCP /multi /IPv6, since about 2016.
The reason for this choice was:
- A simpler implementation
- Lower memory foot print ( a socket is an “expensive” object )
- Simpler application code
On Linux or Windows you can choose between binding to a particular IP address ( 192.168.2.11 ), or binding to the the ANY address 0.0.0.0.
When binding to a particular address like 192.168.2.11:80, one can allow other TCP servers to re-use port 80 by setting the SO_REUSEADDR
option on the socket.
@rtel wrote:
For example, having an HTTP server on 10.10.10.10:80 and 1.2.3.4:80 at the same time.
Exactly.
@RAc wrote:
And you are sure that the IP addresses passed to the two constructors are distinct?
In fact, the binding IP-address is ignored, only the port is what matters.
it looks like you are re using the same MAC address for both cards
That is unfortunate, because that makes routing more difficult.
On FreeRTOS+TCP, you can check the IP-addresses of both sides of a TCP connection with:
BaseType_t FreeRTOS_GetRemoteAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress );
size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket,
struct freertos_sockaddr * pxAddress );
On the basis of this information, you can decide to offer a different type of website.
Most of you will know: a TCP server socket doesn’t do much, it can create a local socket with the same port number as the server.
bind function because I use the same port number for both endpoints
@ozanagma, Could you try the following?
endpoint 1 : 192.168.1.100, mask 255.255.255.0
endpoint 2 : 192.168.2.100, mask 255.255.255.0
Create a socket and bind it to port 17000. Now you can write to both endpoints and the routing should work well.
When a device replies, you can find out who’s replying by checking the parameter pxSourceAddress
.
@rtel wrote:
Yes - two identical MAC addresses on the same subnet is going to cause a problem. Which would respond to an ARP, for example.
That is another reason to give endpoint a unique netmask.
If the above is impossible in your setup, lets think of finding a solution in the library.
Thanks