I've written a C code which creates a socket and it works fine so far. In the RFC for TCP i found out that it is possible to send a FIN flag to tell the other host that i want to quit or conversation. The FIN flag does not mean that the other host isn't able to send more data. So in a perfect world i would send the FIN Flag and the other host knows that i dont want to talk anymore he sends the rest of data and shuts down after that. But how can i send the FIN??? The close() function does that for me or better set the linux kernel does when he puts away the resource. But putting away the resource means that i cant use the recv() function anymore because the file descriptor was put away by the kernel when i called the close() function. So how is it possible to read the rest of data that the other host may wants to send after my FIN flag. I bet there is a clean solution
Asked
Active
Viewed 3,841 times
1 Answers
6
You want to shutdown your write-side of the socket with shutdown(s, SHUT_WR)
.
The
shutdown()
call causes all or part of a full-duplex connection on the socket associated with sockfd to be shut down. If how isSHUT_RD
, further receptions will be disallowed. If how isSHUT_WR
, further transmissions will be disallowed. If how isSHUT_RDWR
, further receptions and transmissions will be disallowed.
See also:

Jonathon Reinhart
- 132,704
- 33
- 254
- 328