I have built a simple client-server architecture, with a multithreaded echo server handling requests from clients. I have implemented this in C and the server and client fully work as expected. However, I have recently come across the setsockopt system call, and I am not able to understand quite clearly why it is needed. Even after adding it to the server code after socket system call, I did not notice any difference in the program.
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
&opt, sizeof(opt)))
Any pointers on why this is really needed? The man pages and other sites don't seem to answer why it is beneficial clearly.