Loco
07-24-2002, 05:36 PM
2.5 - How do I properly close a socket?
This question is usually asked by people who try close(), because they have seen that that is what they are supposed to do, and then run netstat and see that their socket is still active. Yes, close() is the correct method.
From: Alejo
Actually, shutdown is the proper way to close a comunication. You close your end, and then the other part closes hers.
You could close writing, reading or both.
From: Rob Seace
Actually, NO, the FAQ is correct: close() is the correct
method of closing a connection... The only real use for
shutdown() is if you need to close only HALF of a
connection, while leaving the other half active; or, if you
have multiple open FDs referring to the same connection,
and you wish to force a connection close now, without
waiting for the last of them to be close()'d... Otherwise,
plain old close() is quite sufficient...
This question is usually asked by people who try close(), because they have seen that that is what they are supposed to do, and then run netstat and see that their socket is still active. Yes, close() is the correct method.
From: Alejo
Actually, shutdown is the proper way to close a comunication. You close your end, and then the other part closes hers.
You could close writing, reading or both.
From: Rob Seace
Actually, NO, the FAQ is correct: close() is the correct
method of closing a connection... The only real use for
shutdown() is if you need to close only HALF of a
connection, while leaving the other half active; or, if you
have multiple open FDs referring to the same connection,
and you wish to force a connection close now, without
waiting for the last of them to be close()'d... Otherwise,
plain old close() is quite sufficient...