I currently have a .NET program initiating a connection to a server and starting another, unmanaged executable. The native process should take over the same socket (it is essential for the connection not to be closed until the termination of the child process!) and start communicating through it with the server.The aforementioned programs run both on Windows, however I'd prefer a solution that does not involve P/Invoke for the .NET part. As a side note, communication from parent to child process is not an issue so I can easily share data between the two.Furthermore, once I start using the socket from the native process I don't need to use it from the .NET process anymore and the .NET process will terminate before I'm done using the socket from the unmanaged process, thus along with the solution I need to know what to do with the Socket object in .NET so that its disposal doesn't affect the OS socket and its usability.Thanks in advance!
See sample here Socket Duplication - Part 2
Mayevski 'EldoS : MSDN says : The target process should use Socket to create the duplicate socket instance. For an unmanaged process this is not possible I think.
sad_man you're right. There's one more option which I have included to the update.
Thanks for pointing me to DuplicateAndClose. I've ended up writing some very dirty code using P/Invoke calling WSADuplicateSocket but it looks like it'll do the trick, for now :)
I shall also add that I've noticed that when the first process, being a .NET process, terminates, it shuts down the socket regardless of the duplication I've made, so I must first release all other resources, then TerminateProcess so that the socket can't be shut down. Very dirty, but I still haven't found an alternative.
emaster how exactly did you do duplication and socket closing?