Discussion:
How to pass TCP socket handle been process?
(too old to reply)
swathi
2007-07-18 14:16:49 UTC
Permalink
( 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();
Arkady Frenkel
2007-07-21 14:31:52 UTC
Permalink
Look at http://www.tangentsoft.net/wskfaq/articles/passing-sockets.html
Arkady

"swathi" <***@gmail.com> wrote in message news:***@d30g2000prg.googlegroups.com...
( 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();

Continue reading on narkive:
Loading...