Messaging in local network with .NET
I need to implement some form of communication mechanism开发者_JS百科 in my application, to send notifications/messages from one application instance to all the others. This is a normal scenario where someone adds and item or deletes and item and you want to notify other users that this has happened.
The application runs on the client and connects to a database on the local network. So its not like all clients access a server instance of the application. So from what I know I could use MessageQueues or some form of Database polling where I have a table that stores all the messages (not ideal).
Issue is I need to implement this very quickly, so sadly can't go very complex but need the quickest easiest solution.
thanks for the help!
Sounds like it might be easier for you to use optimistic concurrency. Assume that things wont be deleted and deal with it at the affected client when it happens, which should be easier than developing some kind of concurrent notification system that won't scale at all...
Other than that, if you client list is small, db polling is the easiest way to do it without adding another layer of communication to your system, just add a table and implement a class library for everyone to do their thing on, if you can access the DB you are able to find out about deleted items etc.
Rhino Queues should do the trick. Its a super-lightweight queue which doesn't need MSMQ and is XCOPY deployable
http://ayende.com/Blog/archive/2009/04/03/rhino-queues-take-6.aspx
I believe you can do this with WCF. It has a binding for peer to peer communications.
Depending on your network topology the natural choice would be to either a broadcast (same subnet) or multicast over multiple subnets when something new is added.
Broadcasts are rather simple to program, but you need to check first if they are allowed in your network.
I think polling the db is going to be your quickest route. Something real simple like, when a table has a modification made, store the time it happened in another table, using a trigger is one way to do this.
Your clients query that table and compare there locally held modified time, if the db time is newer then refresh.
Anything more than that would become complex..... especially with your 'couple of seconds' requirement.
You could implement all this in a way that could be replaced with more heavyweight method later if required.
You might like to check out my blog post here, which discusses a possible implementation of a cross-process event aggregator.
You must first study Socket programming in C# open these links: http://www.codeproject.com/Articles/10649/An-Introduction-to-Socket-Programming-in-NET-using
http://socketprogramming.blogspot.com/
next if u r a C# developer it will be easy to do so .
精彩评论