I have to write a simple command-line client/server thingy for school and our teacher told us that using fdopen on Sockets is the easy way to go. A protocol is given that defines simple requests and responses only marked by EOF (so not within the request itself but the FIN flag will have to do).
Now my problem is that in order to get a response in the client I have to close the writing direction.
For this I'm using fclose()
Leaving out the details what I'm doing (skipping all the error handling and unrelated stuff)is pretty much:
sdr = socket(..);
writepointer = fdopen(sdw,"w");
readpointer = fdopen(sdr,"r");
Now I would expect flcose() (which successfully return 0 btw) to send EOF, fflush(), close the pointer and close the underlying socket descriptor resulting in a fin flag being sent from the client to the server.
Now when I single step through the program and simultaniously look at tcpdump I see the request being sent (and ack'ed by the server) when I call fclose() but no FIN flag.
This of course results in the Server not seeing that the request is done and my client getting very bored when trying to read a response later on.
I don't find many people using file pointers for tcp transfers here so a search for this didn't yield a whole lot.
Has anyone had this problem before?