How to correctly configure the address of a socket configured as TCP server?


I’m trying to implement a TCP / IP server based on the following tutorial:

Create, Configure and Bind a TCP Socket

But I have a question as to how the IP address is assigned that the router that I imagine has provided it dynamically (DHCP)

The lines of code in question are as follows:

     /* Set the listening port to 10000. */
    xBindAddress.sin_port = ( uint16_t ) 10000;
    xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
    /* Bind the socket to the port that the client RTOS task will send to. */
    FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );

Is that way correct?

or should the following instruction be used?


Thanks for any comments.

Where? You show three lines and I’m not sure where you are suggesting xRemoteAddress.sin_addr is used within those three. In any case, I think the code is correct. There are also examples you can reference in the download. For example here:

Alternatively, but a bit more complicated, within this directory:

1 Like

Hi there.

The TCP / IP server has worked very well, it seems to me that the xRemoteAddress.sin_addr instruction is used when you want a TCP client and it is the IP of the server where you want to connect, otherwise, that is, it is how I initially published.

Thanks for writting