Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket passing between processes

Is there a way to pass a socket between processes (not same address space) in Windows?

I find this info Shared Sockets, therefore believe that it is possible.

"The WSADuplicateSocket function is introduced to enable socket sharing across processes"...

More info : at source code of Apache (httpd-2.2.11-win32-src.zip) have usage for api WSADuplicateSocket with comments.

[EDIT] Recently I find this great sample about this question.
How duplication is done in the unmanaged world - Socket Duplication - Part 1
Is it possible to transfer sockets from unmanaged processes? - Socket Duplication - Part 2

like image 852
lsalamon Avatar asked Mar 02 '09 18:03

lsalamon


People also ask

Can two processes share a socket?

You can share a socket between two (or more) processes in Linux and even Windows. Under Linux (Or POSIX type OS), using fork() will cause the forked child to have copies of all the parent's file descriptors.

Can multiple processes use the same socket?

1 Answer. Save this answer. Show activity on this post. Two processes cannot bind (and listen) to the same unix socket.

Does each process have its own socket?

The system calls for establishing a connection are somewhat different for the client and the server, but both involve the basic construct of a socket. A socket is one end of an interprocess communication channel. The two processes each establish their own socket.

Can processes on the same machine use socket programming?

Sockets allow you to exchange information between processes on the same machine or across a network, distribute work to the most efficient machine, and they easily allow access to centralized data. Socket application program interfaces (APIs) are the network standard for TCP/IP.


2 Answers

See the Remarks section of WSADuplicateSocket. It effectively says you can use Your Favorite Interprocess Communication Scheme to send the WSAPROTOCOL_INFO structure (it's just data!) to the target.

There are lots of IPC schemes. I'd probably use shared memory with Boost::interprocess. But you could use SendMessage if the target has a window + message loop. Or the Clipboard API, for that matter (though somewhat weird). The mechanism is your choice.

like image 199
Jason S Avatar answered Sep 29 '22 20:09

Jason S


If you're creating the child process there are some things that might do it for you. See

http://www.tangentsoft.net/wskfaq/articles/passing-sockets.html (I know that this one worked in the ancient past; no idea if it works on current versions)

http://msdn.microsoft.com/en-us/library/ms682499.aspx

-- MarkusQ

like image 41
MarkusQ Avatar answered Sep 29 '22 21:09

MarkusQ