Create socket in Process1 then pass it to already running Process2 and have Process2 use it
Posted on 2004-04-29
The Setup: I have a client/server environment where Process1 listens for connections on a certain port on a linux server. When a connection request is received from a client process, a new socket is created by accept() and then Process1 is forked. The forked process calls execlp to start Process2 and passes the new socket as a command line argument to Process2. Process2 then communicates via the new socket with the client process who made the original connection request. Process1 continues to listen and repeats this process for each connection request it receives from a client process.
The Issue: There are times where the Client Process and Process2 will temporarily lose their connection with each other (Both processes will continue to exist even when disconnected) . An example of this is when a mobile client machine goes outside the range of a wirless lan and then comes back in. I want to come up with a way that I can get the client process to reconnect to Process2 and pickup where they left off without having to shut down and restart the client process.
Ideal Solution: 1. Client process connects to Process1 and another socket is created via accept()
2. Client process tells Process1 that it has been disconnected from process 2 (Client Process will have the process id of Process2)
3. Process1 then somehow takes the new socket and sends it to Process2 and then process 2 starts using it as it's means of communicating with Client Process. (This one's the kicker and the point to this question)
So, how can I create a socket in process1 and get it to process 2 for use?
I have seen something similar to this done in windows environment with WSADuplicateSocket() and WM_COPYDATA but did not find anything in Linux that mimicks this.