Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My project has two programs: Parent and Child.

In Parent: has one socket waiting connection from client. When Parent accepts connection, it generates Child process and passes socket to Child.

C++
SOCKET newSock = accept(listenSock, 0, 0);
char cmd[1024];
sprintf(cmd, "%s %d", "Child.exe", newSock);
result = CreateProcess( NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInformation);

Client and Child process transfer data successfully.

But when I searches Google and some people wrote that : must call function WSADuplicateSocket(), after that pass socket to child process.

Pleas help me show the different between the two ways?
If i don't call WSADuplicateSocket() whether my program has any error or not?

Thanks!
Posted

1 solution

the problem/error is that your 2 processes are sharing the same socket. If any of them is closing the socket the other process has a huge problem.

My solution wold be to "clear" the ownership by opening the socket ONLY in the child process or use the API as recommended.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900