Client and server applications send and receive disconnect data in a manner similar to the way each sends and receives connect data.
To send disconnect data, a client application calls setsockopt with the SO_DISCDATA option and a buffer of disconnect data to be transmitted to the server on the remote node. This data is sent either when the client application calls shutdown to disconnect the send side of the socket or when the application calls closesocket on the socket.
To receive disconnect data, a client application must call setsockopt with the SO_DISCDATALEN option prior to a remote’s closure of the connection. This option specifies the amount of disconnect data the application expects to receive.
After the remote has disconnected, any server-supplied disconnect data can be retrieved with the SO_DISCDATA option to getsockopt. The client application passes in a buffer large enough to hold all the disconnect data, and Windows Sockets copies the received disconnect data into this buffer.