When should I use shutdown()?

Answer Posted / chaitanya

shutdown() is useful for deliniating when you are done providing a request to a server using TCP. A typical use is to send a request to a server followed by a shutdown(). The server will read your request followed by an EOF (read of 0 on most unix implementations). This tells the server that it has your full request. You then go read blocked on the socket. The server will process your request and send the necessary data back to you followed by a close. When you have finished reading all of the response to your request you will read an EOF thus signifying that you have the whole response. It should be noted the TTCP (TCP for Transactions -- see R. Steven's home page) provides for a better method of tcp transaction management.

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 purpose of socket?

665


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?

1181


What are the pros/cons of select(), non-blocking I/O and SIGIO?

1103


Can a single socket port be used for multiple applications?

621


What is a sae socket?

699






What is socket address?

753


Why does it take so long to detect that the peer died?

1294


What's the difference between a socket and a port?

607


What are the types of sockets?

664


Why do we need sockets?

603


How are unix domain sockets implemented?

632


How do I use TCP_NODELAY?

1241


How many sockets can a port have?

643


What is difference between socket and websocket?

633


How does unix socket work?

658