I am writing a socket program which consists of a bunch of slave processes that will be sitting on each machine in a cluster of computers, while a master process instructs them to move local files over to remote slaves on remote nodes. The primary task of these slave processes is to read files off their local hard disks and transfer them to other slaves on other machines. I want to have this functionality of both listening for file data and sending over file data built into a single process.
Is it possible that I can have both the sending and the receiving bits in the same process ?
//I want this to send a connect() request to every other slave node
initialize_Connections();
//Have an accept() call for accepting the connection requests from the other nodes
accept_Connections();
Is it even possible to pull off something like this ? I looked at forking the process between the initialize_Connections() and the accept_Connections() call (ie a child process calls the initialize_Connections() and the parent takes care of the accept_Connections()) but that did not work out for some mysterious (to me) reason.
Is it possible to use nonblocking connect() and accept() in this situation ?