Jump to content

[Question][C#.NET] Inter-Process Communication

Recommended Posts


For a university assignment, I'm currently writing an application which gathers information given to it by an Arduino device, stores that information in log files which can be read in graphical form and gives a real-time update graph of the results.

The application is designed around a Server Room Automated Sensor Array. The Arduino measures the operational temperature of two servers, the ambient temperature of the room, the level of power in the two UPSs and (using a Throwing Star LAN Tap) monitors whether the redundant trunk line is in use or not. If it is, it alerts that the main trunk line is faulty.

I would like to code this as two/three separate applications. First will be the backbone. A daemon application which just sits there and collects the information, writes log files and fires off events whenever data is received.

The second application will connect to the daemon and listen to the events being fired and update a live streaming graph (Currently using Microsoft Charting). As well as this, or maybe in a third application, it will allow the user to display graphs and data generated from the log files (saved as a 24hour log).

I'm using an Event Driven Observer pattern for the whole project.

I have the daemon (ardsvrmond.exe) working, perfectly as a Console Application. It just sits there firing off events and writing logs all day long. I'm using the following line keeping it open as a daemon:

// Keep the application open to listen to events.
new System.Threading.AutoResetEvent(false).WaitOne();

But, now, what is the best way to make an IPC call to or hook on to the ardsvrmond.exe process so that the second application can subscribe to its events?

Link to comment
Share on other sites

I'm not a programmer, but maybe I missed something on that last line question.

But, now, what is the best way to make an IPC call to or hook on to the ardsvrmond.exe process so that the second application can subscribe to its events?

The main daemon just writes logs, no? Wouldn't it be easier, if the second application was just a listener, and you can assign event ID's in the first daemon to specific events, where, if one event id for something that went wrong happens, it sends a message tot he second application, instead of the second application trying to subscribe, or in my mind "query" for the event has happened. Like an open TCP socket that listens on a post(say an open shell for commands like a netcat listener, but just using as example, not for true implementation since thats very dangerous) you could make the second program just another daemon that waits and listens and when daemon 1 catches specific events, it just shoots a packet with the event ID to the second daemon that does xyz, or whatever your next step is, such as emailing admins, sending sms messages, etc.

That way, daemon 1 (ardsvrmond.exe) continues to run and just chug along, while daemon 2 just waits for specific event ID's. Then daemon 2 can be programmed to know what each event ID is defined as, and send the corresponding event ID but also definition with the message to wherever it has to go to do its processing and output to whomever is to receive it.

Also, not to reinvent the wheel here, getting temperatures from the OS, can be done on the OS itself usually with queries to itself and monitored over things like SNMP, although you might want to use your arduino method, so you can build your own protocol, and encrypt it, since SNMP can lead to vulnerabilities and queries of a lot of things you don't want getting let out in the wild.

Oh, forgot about program 3 - This could be something that just reads like, the last 1000 lines from deamon 1's logs, in real time and outputs in in XML or RSS fashion that can be displayed in a web browser and update asynchronously in real type either by ajax or xmlhtto requests that shows your graphs, events, time stamps, etc, or creates readable reports for monthly charts by reformatting it to CSV files to show whatever you want. Just an idea.

Edited by digip
Link to comment
Share on other sites

I've gone with using a Duplex named pipe for the IPC. It's working steadily, throwing messages out to the client, it's all working quite nicely. But the Wrapper Class I've got for it is not very well written at all and isn't as robust as I'd like.


I've been looking for something similar to this, but defensively programmed.

I don't really want to get into WCF if possible; Microsoft, yet again, writing 12,000 lines of code so that you can use it in every eventuality, when you only need it for one specific purpose. The MSDN isn't much help either. Their examples leave much to be desired usually. Because it's predominantly a broadcast daemon, I'm putting the emphasis mainly on defensive capabilities of the and fallback methods of the server. The client only ever needs to send two requests; one to connect and one to disconnect. So far as I can tell with the Named Pipes, you can only send data if there is a client connected; only once client can connect at a time and once they disconnect, the pipe doesn't reset itself. I've managed to get around the last with two threads (connection and communication) which just bounce back to one another when a user connected then disconnects.

Link to comment
Share on other sites

As with the point of getting temperatures from the BIOS or from wherever else, the project is majorly about collating Arduino data. I'm basing it in a Server Room because of the nature of the course we're doing and my prior work experience. If I'm honest, measuring temperature is a bit of a cop out with Arduino because it's only three wires and no extra components, just a TMP36.

But, it does have a real world application. When I worked as SysAdmin in a college, I got a phone call one Sunday morning at about 4:30 AM: "This is an automated call from the <College Name> Server. A situation has arisen which requires your attention as a key holder. Sensors indicate most probable cause, Fire. Emergency Services have been called. Please attend immediately." I only lived about 10 minutes away and I arrived just before the fire brigade and police turned up. Turned out the cherry blossom outside had clogged all the air vents to the server room. The ambient temperature in the room itself was over 45 degrees and there was blinking lights and alarms going off on everything. Luckily it hadn't done any damage, but that system saved the college, and all its students. I'd like to mimic something like it. I remember we had to constantly check the UPS batteries as well; big heavy bastards that had a tendency to leak if placed to close together and didn't like being moved. Automating that would save a huge amount of time and hassle. And I wanted to find some way of paying homage to Hak5; hence the Throwing Star. I've put a few Technolust easter eggs in a fair few of my assignments so far. :)

Link to comment
Share on other sites

  • 2 weeks later...

I ended up using 0MQ (http://zguide.zeromq.org/page:all), which makes it wonderfully easy to create various forms of message queues. I'm using the Pub/Sub pattern over TCP on port 2600.

ZMQ.Context context = new ZMQ.Context(1);
ZMQ.Socket publisher = context.Socket(ZMQ.SocketType.PUB);
publisher.Bind("tcp:\\*:2600"); \\ Or publisher.Bind(ZMQ.Transport.TCP, "*", 2600);
publisher.Send("Hello World!", Encoding.Unicode);

The library works in the following languages:

C++ | C# | Clojure | CL | Delphi | Erlang | F# | Felix | Go | Haskell | Haxe | Java | Lua | Node.js | Objective-C | Perl | PHP | Python | Racket | Ruby | Scala | Tcl | Ada | Basic | ooc | Q
It's one of the most versatile libraries I've ever seen. :D
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...