As we known that:
/////////////////////////////////////////////////////////
close() will terminate both directions on a tcp connection
shutdown() can block communication in one or both directions
/////////////////////////////////////////////////////////
here,what puzzled me is how tcp stack can tell them apart?
I have write an example program:
firstly I use :
....
connect(192.168.1.100) //there is a server process running in 192.168.1.100
....
close(socketfd);
sleep(1000);
then I use wireshark to dump the packets:
01 -->syn
02 <--syn,ack
03 -->ack
04 -->fin,ack
05 <--ack
netstat -an |grep 192.168.1.100
I have run it for about 5 minutes, it print:
"tcp 0 0 ... FIN_WAIT2 " at first,then after about 2 minutes there is no output,seems that the connection has been destroyed.
then, I use :
....
connect(192.168.1.100)
....
shutdown(socketfd,SHUT_WR);
sleep(1000);
use wireshark to dump the packets:
01 -->syn
02 <--syn,ack
03 -->ack
04 -->fin,ack
05 <--ack
...
netstat -an |grep 192.168.1.100
run it for about 10 minutes, it always print: "tcp 0 0 ... FIN_WAIT2"
from the output of wireshark ,it seems there is no different for close and shutdown,
but from the output of netstat ,its behaviour is different.
so why the behaviour is different?