What is the difference between close() and shutdown()?
Answer / chaitanya
Generally the difference between close() and shutdown() is: close() closes the socket id for the process but the connection is still opened if another process shares this socket id. The connection stays opened both for read and write, and sometimes this is very important. shutdown() breaks the connection for all processes sharing the socket id. Those who try to read will detect EOF, and those who try to write will reseive SIGPIPE, possibly delayed while the kernel socket buffer will be filled. Additionally, shutdown() has a second argument which denotes how to close the connection: 0 means to disable further reading, 1 to disable writing and 2 disables both.
| Is This Answer Correct ? | 0 Yes | 0 No |
How come I get address already in use from bind()?
How come only the first part of my datagram is getting through?
What is the difference between SO_REUSEADDR and SO_REUSEPORT?
How can I be sure that UDP messages are received in order?
How can I put a timeout on connect()?
How should I choose a port number for my server?
How can I listen on more than one port at a time?
How many sockets can a cpu have?
What are raw sockets?
What is a socket set used for?
How many sockets can a port have?
When should I use shutdown()?