Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a socket to a new AppDomain

I'm working on porting a client/server application to .NET. The current C version of the server has one executable for a process (a Windows service) that listens for socket connections. When the listener accepts a socket connection it spawns a new process to handle that connection. The handler application is a separate executable.

In the .NET version of this application, I'd like to have one executable/process. The listener should create a new AppDomain for each connection (to isolate the "worker process" assigned to each client). How should I pass the socket from the listener app domain to the worker app domain?

Thanks!

like image 298
Matt Varblow Avatar asked Aug 15 '11 15:08

Matt Varblow


1 Answers

I think I just found the answer to my own question. The DuplicateAndClose method can be used even though I'm not passing the socket to a separate process. The listener can just pass in its own process ID to DuplicateAndClose.

The solution is described here: http://blogs.msdn.com/b/malarch/archive/2005/12/14/503884.aspx

This also works if you want to pass the socket off to a separate process.

like image 79
Matt Varblow Avatar answered Nov 05 '22 08:11

Matt Varblow