swathi
2007-07-18 14:16:49 UTC
( C++ in VC++6.0 IDE )
In serverProcess I will create pipe(name pipe or anonymous pipe) and
spawn process( slaveProvess).then I crated Tcp socket,
When ever it accepted new TCP socket I want to send this accepted
socket handle to slaveprocess.exe through pipe then slaveprocess read
accepted socket handle from pipe and do socket read operations .
But at slaveProcess socket read giving error
10038 An operation was attempted on something that is not a socket.
So how to pass socket handle between process
Here is basic code
in masterProcess.exe
hPipe=CreateNamedPipe(\\\\.\\Pipe\\MyNamedPipe)
CreateProcess(slaveProcess.exe)
ConnectNamedPipe(hPipe)
Create TCP socket
Bind
listen
while(1)
{
Acceptfd=accept()
_itoa(Acceptfd, szBuffer, 10 );//< is this correct way to do
WriteFile(hPipe, szBuffer)
}
In slaveProcess.exe
hPipe = CreateFile(\\\\.\\Pipe\\MyNamedPipe)
ReadFile(hPipe ,buffer)
SOCKET socketfd= (SOCKET)atoi(buffer); );//< is this correct way to
do
int ret1=recv(sockfd,serverbuff,1024,0);
int err=WSAGetLastError();
In serverProcess I will create pipe(name pipe or anonymous pipe) and
spawn process( slaveProvess).then I crated Tcp socket,
When ever it accepted new TCP socket I want to send this accepted
socket handle to slaveprocess.exe through pipe then slaveprocess read
accepted socket handle from pipe and do socket read operations .
But at slaveProcess socket read giving error
10038 An operation was attempted on something that is not a socket.
So how to pass socket handle between process
Here is basic code
in masterProcess.exe
hPipe=CreateNamedPipe(\\\\.\\Pipe\\MyNamedPipe)
CreateProcess(slaveProcess.exe)
ConnectNamedPipe(hPipe)
Create TCP socket
Bind
listen
while(1)
{
Acceptfd=accept()
_itoa(Acceptfd, szBuffer, 10 );//< is this correct way to do
WriteFile(hPipe, szBuffer)
}
In slaveProcess.exe
hPipe = CreateFile(\\\\.\\Pipe\\MyNamedPipe)
ReadFile(hPipe ,buffer)
SOCKET socketfd= (SOCKET)atoi(buffer); );//< is this correct way to
do
int ret1=recv(sockfd,serverbuff,1024,0);
int err=WSAGetLastError();