I have written a multiclient Server program in C on SuSE Linux Enterprise Server 12.3 (x86_64), I am using one thread per client to receive data.
My problem is:
I am using one terminal to run the server, and using several other terminals to telnet
to my server (as client). I have used recv()
in the server to receive data from client, I have also applied checks for return value of recv()
i.e. Error on -1
; Conn. Closed on 0
& Normal operation else. I have not used any flags in recv()
.
My program works fine if I just close the telnet session (i.e. disconnect client) normally using Ctrl+]
and close
, but if I forcefully terminate the client using kill <pid>
then my server is unable to detect loss of connection.
How to fix that?
Constraint: I do not want to put condition on client side, I want to fix this on server side only.