[Mono-dev] Interprocess communication
Steve Bjorg
steveb at mindtouch.com
Thu Dec 27 00:27:28 EST 2007
You could use TcpSocket or HttpListener over localhost (loopback).
Using HttpListener is rather straightforward:
string connectionEndPoint = "http://localhost:8888";
//*** setting up the listener ***
HttpListener listener = new HttpListener();
listener.Prefixes.Add(connectionEndPoint);
listener.Start();
AsyncCallback callback = delegate(IAsyncResult ar) {
HttpListenerContext httpContext = listener.EndGetContext(ar);
//--- do your processing here ---
listener.BeginGetContext(callback, listener);
};
listener.BeginGetContext(callback, listener);
//*** sending a message ***
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create
(connectionEndPoint);
httpRequest.Method = "POST";
using(Stream stream = httpRequest.GetRequestStream()) {
stream.Write(data, 0, date.Length);
}
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
bool success = (httpResponse.StatusCode >= 200) &&
(httpResponse.StatusCode < 300);
httpResponse.Close()
Package this into helper functions and make the connection end point
configurable and voila, portable cross process communication. This
is also a great launch pad into making your system network
distributed if need be as well as take advantage of the various
object seriializers in .net and mono.
- Steve
--------------
Steve G. Bjorg
http://wiki.mindtouch.com
http://wiki.opengarden.org
On Dec 26, 2007, at 8:43 PM, Justin Cherniak wrote:
> Unfortunately as far as I know there is no easy one off way to do
> this. That said, if you are communicating to an unmanaged process,
> I would assume it is a safe assumption to assume you are targeting
> a particular operating system.
>
> I can't help you much with *nix, but on windows, you have a number
> of options including:
> COM
> Shared memory
> Window messages
> What exactly are you trying to do, I (or someone else) might be
> able to narrow it down to a clearer solution.
>
> Thanks,
> Justin
>
> On Dec 26, 2007 10:21 PM, FirstName LastName
> <mousse_man at hotmail.com> wrote:
> Hi,
>
> I'm currently trying to find a way to make 2 processes on the same
> machine talk.
>
> One process is managed while the other is unmanaged. How can I do
> this?
>
> Thanks!
>
> HO HO HO, if you've been nice this year, email Santa! Visit
> asksanta.ca to learn more!
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071226/91651f80/attachment.html
More information about the Mono-devel-list
mailing list