Wednesday, September 21, 2011

closing socket in c


Closing Sockets

Previously, you saw how a pair of sockets could be easily created and how some elementary input and output can be performed using those sockets. You also saw that these sockets could be closed in the same manner that files are with the use of the close(2) function call. It's now time that you learn what is implied by the closing of a socket. When reading from a pipe created by the pipe(2) function, the receiving end recognizes that there will be no more data when an end-of-file is received. The end-of-file condition is sent by the writing process, when it closes the write end of the pipe.

This same procedure can be used with a pair of sockets. The receiving end will receive an end-of file indication when the other endpoint (socket) has been closed. The problem develops when the local process wants to signal to the remote endpoint that there is no more data to be received. If the local process closes its socket, this much will be accomplished.

However, if it needs to receive a confirmation from the remote end, it cannot, because its socket is now closed. Situations like these require a means to half close a socket.

No comments:

Post a Comment