How do I properly close a socket?

Answer Posted / chaitanya

This question is usually asked by people who try close(), because they have seen that that is what they are supposed to do, and then run netstat and see that their socket is still active. Yes, close() is the correct method. To read about the TIME_WAIT state, and why it is important, refer to ``2.7 Please explain the TIME_WAIT state.''.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between SO_REUSEADDR and SO_REUSEPORT?

1356


system choose one for me on the connect() call? Should I bind() a port number in my client program, or let the?

1165


What is socket address?

578


How do I convert a string into an internet address?

910


What is the difference between a socket and a port?

467






How do unix sockets work?

494


What is a socket api?

533


What does af mean in sockets?

526


What is a deep well socket?

528


Can a single socket port be used for multiple applications?

458


How can I force a socket to send the data in its buffer?

1099


What is the function of socket?

516


How can I set the timeout for the connect() system call?

1114


Is tcp or unix socket faster?

496


How can I tell when a socket is closed on the other end?

975