Sharing of Socket handles between process 
Author Message
 Sharing of Socket handles between process

Hello,

Is it possible to pass a connection handle created in one process (.exe) to
another process (.exe) ?

Regards
Suchrithaa



Sun, 11 Sep 2005 21:30:19 GMT  
 Sharing of Socket handles between process

Quote:

> Hello,

> Is it possible to pass a connection handle created in one process
> (.exe) to another process (.exe) ?

Yes.  You need to use DuplicateHandle to create a handle for the destination
process.  Individual Handle values are always unique to the process that
created them.

-cd



Sun, 11 Sep 2005 22:19:27 GMT  
 Sharing of Socket handles between process
Usually you can use DuplicateHandle.

I do this in a few of my apps and recently I've run into trouble on a few
installations that have LSP's installed (Layered Service Providers).
Calling DuplicateHandle does not work in these cases - you have to use
WSADuplicateSocket() instead.

DuplicateHandle will succeed, but the duplicated socket will not be usable
in the child process - you get error 10038's (not a valid socket) when you
try to use it.

Unfortunately, WSADuplicateSocket() does not simply return a DWORD handle to
pass to the child - it returns a struct, so you have to pass the entire
struct to the child.  Most examples that use DuplicateHandle simply pass the
DWORD handle value on the command line to the child, but that doesn't work
with WSADuplicateSocket because there is much more to pass.  :-(



Quote:

> > Hello,

> > Is it possible to pass a connection handle created in one process
> > (.exe) to another process (.exe) ?

> Yes.  You need to use DuplicateHandle to create a handle for the
destination
> process.  Individual Handle values are always unique to the process that
> created them.

> -cd



Sun, 11 Sep 2005 23:09:09 GMT  
 Sharing of Socket handles between process
Hello

Thanks for the info.

Is the LSP concept available on Windows CE or is this valid for normal
Windows Platforms also (i mean Win 98/.NET/XP/2K/XP/? I read about LSP in
the following URL and thereby I came across this question.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcew...
m/ceconlayeredserviceprovider.asp

In my case I need to invoke the child process dynamically.  So, should I
pass the struct returned by WSADuplicateSocket() as a command line parameter
to the Child process?

Regards
Suchrithaa


Quote:
> Usually you can use DuplicateHandle.

> I do this in a few of my apps and recently I've run into trouble on a few
> installations that have LSP's installed (Layered Service Providers).
> Calling DuplicateHandle does not work in these cases - you have to use
> WSADuplicateSocket() instead.

> DuplicateHandle will succeed, but the duplicated socket will not be usable
> in the child process - you get error 10038's (not a valid socket) when you
> try to use it.

> Unfortunately, WSADuplicateSocket() does not simply return a DWORD handle
to
> pass to the child - it returns a struct, so you have to pass the entire
> struct to the child.  Most examples that use DuplicateHandle simply pass
the
> DWORD handle value on the command line to the child, but that doesn't work
> with WSADuplicateSocket because there is much more to pass.  :-(




> > > Hello,

> > > Is it possible to pass a connection handle created in one process
> > > (.exe) to another process (.exe) ?

> > Yes.  You need to use DuplicateHandle to create a handle for the
> destination
> > process.  Individual Handle values are always unique to the process that
> > created them.

> > -cd



Tue, 13 Sep 2005 13:45:37 GMT  
 Sharing of Socket handles between process
I don't know about Windows CE, but I have personally only encountered LSP's
on Windows 2000 systems (so far).

It is difficult to pass the WSADuplicateSocket struct on the command line
because there are several fields in the struct.  I suppose you could pass
them (each field separately, with quotes around each) and re-assemble the
struct in the child process by using argv[].  It may not be pretty.

It might be easier to pass the struct in a temp file (I use a memory mapped
file for speed, but it is the same concept).  Get a temp filename using API
calls, fwrite() the struct to the file, then pass the name of the file on
the command line to the child process.  Then just have the child process
fread() the file back into its struct.


Quote:
> Hello

> Thanks for the info.

> Is the LSP concept available on Windows CE or is this valid for normal
> Windows Platforms also (i mean Win 98/.NET/XP/2K/XP/? I read about LSP in
> the following URL and thereby I came across this question.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcew...
Quote:
> m/ceconlayeredserviceprovider.asp

> In my case I need to invoke the child process dynamically.  So, should I
> pass the struct returned by WSADuplicateSocket() as a command line
parameter
> to the Child process?

> Regards
> Suchrithaa



> > Usually you can use DuplicateHandle.

> > I do this in a few of my apps and recently I've run into trouble on a
few
> > installations that have LSP's installed (Layered Service Providers).
> > Calling DuplicateHandle does not work in these cases - you have to use
> > WSADuplicateSocket() instead.

> > DuplicateHandle will succeed, but the duplicated socket will not be
usable
> > in the child process - you get error 10038's (not a valid socket) when
you
> > try to use it.

> > Unfortunately, WSADuplicateSocket() does not simply return a DWORD
handle
> to
> > pass to the child - it returns a struct, so you have to pass the entire
> > struct to the child.  Most examples that use DuplicateHandle simply pass
> the
> > DWORD handle value on the command line to the child, but that doesn't
work
> > with WSADuplicateSocket because there is much more to pass.  :-(




> > > > Hello,

> > > > Is it possible to pass a connection handle created in one process
> > > > (.exe) to another process (.exe) ?

> > > Yes.  You need to use DuplicateHandle to create a handle for the
> > destination
> > > process.  Individual Handle values are always unique to the process
that
> > > created them.

> > > -cd



Wed, 14 Sep 2005 08:15:31 GMT  
 Sharing of Socket handles between process
Again thanks for the info.

Regards
Suchrithaa


Quote:
> I don't know about Windows CE, but I have personally only encountered
LSP's
> on Windows 2000 systems (so far).

> It is difficult to pass the WSADuplicateSocket struct on the command line
> because there are several fields in the struct.  I suppose you could pass
> them (each field separately, with quotes around each) and re-assemble the
> struct in the child process by using argv[].  It may not be pretty.

> It might be easier to pass the struct in a temp file (I use a memory
mapped
> file for speed, but it is the same concept).  Get a temp filename using
API
> calls, fwrite() the struct to the file, then pass the name of the file on
> the command line to the child process.  Then just have the child process
> fread() the file back into its struct.



> > Hello

> > Thanks for the info.

> > Is the LSP concept available on Windows CE or is this valid for normal
> > Windows Platforms also (i mean Win 98/.NET/XP/2K/XP/? I read about LSP
in
> > the following URL and thereby I came across this question.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcew...

- Show quoted text -

Quote:
> > m/ceconlayeredserviceprovider.asp

> > In my case I need to invoke the child process dynamically.  So, should I
> > pass the struct returned by WSADuplicateSocket() as a command line
> parameter
> > to the Child process?

> > Regards
> > Suchrithaa



> > > Usually you can use DuplicateHandle.

> > > I do this in a few of my apps and recently I've run into trouble on a
> few
> > > installations that have LSP's installed (Layered Service Providers).
> > > Calling DuplicateHandle does not work in these cases - you have to use
> > > WSADuplicateSocket() instead.

> > > DuplicateHandle will succeed, but the duplicated socket will not be
> usable
> > > in the child process - you get error 10038's (not a valid socket) when
> you
> > > try to use it.

> > > Unfortunately, WSADuplicateSocket() does not simply return a DWORD
> handle
> > to
> > > pass to the child - it returns a struct, so you have to pass the
entire
> > > struct to the child.  Most examples that use DuplicateHandle simply
pass
> > the
> > > DWORD handle value on the command line to the child, but that doesn't
> work
> > > with WSADuplicateSocket because there is much more to pass.  :-(




> > > > > Hello,

> > > > > Is it possible to pass a connection handle created in one process
> > > > > (.exe) to another process (.exe) ?

> > > > Yes.  You need to use DuplicateHandle to create a handle for the
> > > destination
> > > > process.  Individual Handle values are always unique to the process
> that
> > > > created them.

> > > > -cd



Fri, 16 Sep 2005 13:17:48 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Sockets sharing across different processes

2. How to share a socket between different process

3. ? Passing Socket handle to process via pipe

4. Passing Socket handles across process boundaries??

5. sharing variables accros processes & process starting

6. how get a process HANDLE from a thread HANDLE

7. Process id from process handle (how to get)?

8. How to obtain Process ID If I have process handle

9. Get a CWnd Handle from Process Handle

10. Process ID from Process Handle

11. Process ID from Process Handle

12. Window handle from process handle?

 

 
Powered by phpBB® Forum Software