Hello i have a very simple question,
i Have a simple socket server/client program in C
I would like the server side program to keep accepting new connections forever
I want it to be able to accept more connection while it is also performing orther operations
So my question is : what is the best way to do that ?
-should i fork and do accept loop in my child process ?
-should i fork and do accept loop in the parent process, and keep running my operation in the child process ?
Or is there an orther way better than using fork ?
Thank you, bye bye
select()
in a single thread, and that thread can do non-blocking I/O operations on both the accepting-socket and all the other sockets that have been returned viaaccept()
. That's how I usually do it; whether it's preferable or not depends a lot on what sort of program you are trying to create (and in particular whether the functionality provided to the various TCP connections need to communicate with each other much, or not) – Jeremy Friesnersocket
to an idle thread. That thread marks itself as busy, then does all the communication with that individual client, then when all done, closes that socket and marks itself as idle – user3629249