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.

TM4C1294NCPDT: How to close lwip socket.

Part Number: TM4C1294NCPDT

Hi

I used tivaware and lwip-1.4.1 in my application.

It's RAW socket.

I find tcp_close and tcp_abort function, but those function only free pcb, the socket still listening.

How do I close socket?

Please help me to solve it.

Thank you very much!

Allen

  • Hi,

     Please refer to this link on the details.  Below is a snippet of the description. The host you are talking to needs to acknowledge the close. 

  • Hi Charles

    When the recv function  closing connection, it will call function below.

    	tcp_arg(pcb, NULL);
    	tcp_sent(pcb, NULL);
    	tcp_recv(pcb, NULL);
    	mem_free(hs);
    	tcp_close(pcb);

    I used wireshark to observe packet, and observed complete FIN packet.

    The connection was closed, but socket still listening.(Remote host initiate SYN, lwip will accept.)

    Because my application had other communication interface, when the interface changing, I need to close socket and stop listening(completely closed).

    Sorry, this is my first time to use RAW socket.

    Please correct me if anything wrong.

    Allen

  • Are you the server or client?

    Please check out this link www.cs.miami.edu/.../tcp_nutshell.html about the connection finish. You may have a half-close connection. Did the remote host also send a FIN packet to you to fully complete the connection?
  • Hi Charles

    Thanks for your reply.

    It's server.
    I checked with wireshark. The server and client had finish the 4 handshake.
    Sorry I forgot to tell you one thing.
    I had external input button to MCU, it could switching MCU's communication interface.
    When interface switched, I need socket stop listen.
    So I need a way to let socket stop listen, closed.(After server and client finish the fully close connection.)

    Thank you!

    Allen
  • Perhaps try (tcp_abort) tears down the stacks TCP socket connection. UDP socket may not be affected, seemingly (udp_abort) should exist in LWIP too.
  • Hi Allen,
    Does BP101's suggestion help?
    If you are switching from one comm interface to another, can you first disable the Ethernet after you complete the 4 handshake between the server and the client. There are API's such as EMACTxDisable and EMACRxDisable that you can try. Not that it is the best solution but just sometime to also explore. You might want to also check the LwIP forum for advices if there are other ways to completely terminate the connection.