What is the difference between close() and shutdown()?
Answer Posted / 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 |
Post New Answer View All Answers
How does unix socket work?
Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?
Can a single socket port be used for multiple applications?
How can I force a socket to send the data in its buffer?
How can I write a multi-homed server?
What does af mean in sockets?
What is the function of socket?
Where is the socket located?
What is a socket file?
Why does it take so long to detect that the peer died?
Is tcp or unix socket faster?
Can a socket have multiple ports?
What is difference between socket () and serversocket () class?
What exactly is a socket?
What is the difference between a socket and a port?