I am new to network programming. I am on Linux, and I am using C++, the sockets API, and process API. I am trying to understand if what I am trying to do is possible or not.
The goal of my program is to create a game server for Chess. This server will listen to new connections using a socket that it sets up. For every two new connections (a.k.a two new players looking for a match), it will open up a new process that will be conducting the actual game by waiting for input during each turn and relaying it to the other player.
My question then is, how do I actually pass the connections to the child process so that they can communicate with the two players without needing to involve the parent process? Is it possible to just pass the resulting file descriptors when accepting the new connections as command-line arguments to the child process?
I am aware that if I only use fork()
and not exec()
after, then the file descriptor will be shared with the child process automatically, but I want to load a separate executable so that it will be easier to separate the logic between the parent process and child process.