4

Using .net and w/o using something platform specific is there a way i can get two of my apps to poke eachother? Both apps will be running. This specifically will be a one way poke. I'll need to pass it an int64 value minimum. It will run on linux with mono but i'll be developing on windows

-edit- additional info. One process will be asp.net so that means i cant take long to do the poke. The lifetime will be <50ms because its a page request. Also i may have any write/poke request per minute or one every 10+minutes

4 Answers4

1

One approach we've used successfully is Named Pipes. In .net 3.5 they added native support so you don't have to use p/invoke to get at the appropriate win32 APIs.

Check out: http://www.switchonthecode.com/tutorials/dotnet-35-adds-named-pipes-support as an example.

In short, what you'll be doing is creating a client/server mechanism (the "named pipe") which has a specified name; the server will set up the pipe and await client connections...the client will connect to the pipe and send data across it.

The nice thing about this is you can send entire data structures easily (provided they're marked [Serializable]). This allows you to implement particular messages richly (and this includes Enums, too)

One thing to note: by default named pipes are synchronous (blocking) so your call to Connect() will run ~forever if the server is not up. You can either use the asynchronous mode or run your synchronous code in a Thread which you can later abandon/abort. Just keep that in mind when laying the groundwork as the switch to asynchronous pipe usage may be a bit of work if you haven't planned for it.

[Serializable]
public enum CmdType
{
    cmdTypeOne,
    someOtherCmdType
}

[Serializable]
public class Command
{
  CmdType eCmdType;
  // other command payload
}
Will Chesterfield
  • 1,780
  • 12
  • 15
  • Do they exist in Mono as OP asked? – Eugene Mayevski 'Callback Oct 03 '11 at 17:24
  • hmm good answer. I made an edit to my question. Lets say my name pipe server crashes. What happens when i get a POST request and try connecting to the pipe? I cant have the page wait more then 500ms (i prefer if its 50ms or less). Do you have any thoughts on how to ease the blocking part? also when the process boots up does everything i need. I just poke it to wake it up –  Oct 03 '11 at 17:25
1

You could use WCF (supposed to be part of the core stack for Mono) - see this question.

Alternately you could use messaging, such as JMS. Apache ActiveMQ supports C# clients. (We're investigating this but have not tried it in production.)

Either of these solutions could work even if the processes were running on different machines, which makes them more scalable.

Based on your edit, messaging may be a better solution as it is inherently asynchronous.

Community
  • 1
  • 1
TrueWill
  • 25,132
  • 10
  • 101
  • 150
  • ah crap. ActiveMQ requires java and i dont have java on my server. –  Oct 03 '11 at 17:29
  • There are other options such as RabbitMQ (which requires Erlang, though). Is installing Java on the server an option? – TrueWill Oct 03 '11 at 17:35
  • And there are an insane number of other options: http://stackoverflow.com/questions/731233/activemq-or-rabbitmq-or-zeromq-or – TrueWill Oct 03 '11 at 17:39
0

Named pipes might be a possible solution. There is a very detailed article over at CodeProject that shows an example. The articles starts out with:

Have you ever needed to exchange data between two .NET applications running on the same machine? For example a web site talking to a Windows service? The .NET Framework provides several good options for inter-process communication (IPC) like Web services and Remoting, the fastest being Remoting with a TCP channel and binary formatter.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
  • hmm good answer. I made an edit to my question. Lets say my name pipe server crashes. What happens when i get a POST request and try connecting to the pipe? I cant have the page wait more then 500ms (i prefer if its 50ms or less). Do you have any thoughts on how to ease the blocking part? also when the process boots up does everything i need. I just poke it to wake it up –  Oct 03 '11 at 17:25
0

Memory-mapped files are fast. Though the APIs are very different so you would have to write a wrapper with P/Invokes to have a platform-independent way to use it. Our MsgConnect product has MMF transport which would solve your problem, if using third-party solutions is ok for you. Of course, for your quite narrow task you can craft something similar yourself.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121