This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129xx TI-RTOS NDK TCP/IP Socket Re-connect Issue

Hi,

We have issue with the NDK TCP/IP communication on TM4C129xx.
The network doesn't work properly during re-connection.

Currently one of our customer is trying to build a server application 
with TM4C129xx, where a task is executed inside Network open hook function 
and the settings of IPAddress, Subnet, gateway etc are done in CfgAddEntry()
and re-connection is executed immediately if there is a disconnection with the Client, . 

・Device used  :TM4C1294NCPDTI
・IDE  :CCS v6.0.0
・OS    :TI-RTOS 2.01.00.03
    :bios_6_40_03_39
    :ndk_2_23_01_01

Problem:
After the disconnection from the client,we are not able to re-connect.

Failure Procedure.

1.After connecting server to the client, disconnect from the Client
2.Close the Client Socket and Server socket with fdclose() and 
  again create the Server socket with socket() function.
3.It fails in bind() and the fdError() is 「48」

Please let us know if there is any way to solve this issue.

Best Regards

  • Moving it to the TI-RTOS Forum
  • Can you please attach a simple CCS project that demonstrates your issue and instructions on how to reproduce it? Please provide a host application if needed.

    I want to see what socket options you are setting also (e.g. SO_REUSEADDR).

    Todd

  • Hi Todd,

    Thank you for your quick reply!!

    Our customer code is below.

    int si32_rsts;

    SOCKET si32_sockfd = INVALID_SOCKET;
    struct sockaddr_in st_sockaddr;
    int si32_optval;
    int si32_optlen = sizeof(si32_optval);

    si32_sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    si32_rsts = setsockopt(si32_sockfd, SOL_SOCKET, SO_REUSEADDR, &si32_optval, si32_optlen);
    si32_rsts = setsockopt(si32_sockfd, SOL_SOCKET, SO_REUSEPORT, &si32_optval, si32_optlen);
    si32_rsts = setsockopt(si32_sockfd, SOL_SOCKET, SO_KEEPALIVE, &si32_optval, si32_optlen);
    si32_rsts = setsockopt(si32_sockfd, SOL_SOCKET, TCP_NODELAY, &si32_optval, si32_optlen);
    st_sockaddr.sin_family = AF_INET;
    st_sockaddr.sin_len = sizeof(st_sockaddr);
    st_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    st_sockaddr.sin_port = htons(502);
    si32_rsts = bind(si32_sockfd, (struct sockaddr *)&st_sockaddr, sizeof(st_sockaddr));

    Please let us know if there is any way to solve this issue.

    Best Regards

  • Sorry. I have a big backlog. I'll get to your thread soon.

    Todd
  • Hi,

    Thank you for the reply.
    We appreciate your support.
    Shall wait for your reply.

    Best Regards

  • errno 48 is EADDRINUSE. Are you sure you are closing the sockets correctly?

    Just to make sure I have the setup...
    - The TM4C is the server and creates and binds a socket to port 502
    - The TM4C is the server waits in "accept" for incoming packets
    - Some other device is the client and it connects to port 502 on the TM4C
    What does the server do? Does it hand the fd returned from accept off to another task or use it directly in the task.
    When the client disconnects, you need to close the one returned from accept. Why are you recreating the original socket. Why not just go into accept again?

    I'm guessing here since I don't have a snapshot of all the code. If you could attach an exported CCS project, I could tell better.

    Todd
  • Hi Todd,

    Thank you for the reply.
    And we are sorry for the delay in reply.
    We were able to solve the issue.

    As per your suggestion, the sockets were not closed properly.

    We appreciate your support.

    Best Regards
    tmatsu