3

I wanted to set up a simple data communication between two C# applications, and I'm not sure what the best method is in doing so. I've previously used Java Sockets and ServerSockets to get the job done, but I'm new to C#, so I've come for advice :) It's going to be two way communication with two clients exchanging strings or something of the like.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
IronManIngellis
  • 111
  • 1
  • 1
  • 8
  • I think you should be a bit more precise. What are your "C# applications" for example? Web-apps? Windows forms? Something else? And where do they "live"? On the same machine? On a LAN? On the internet? It would slightly surprise me if someone was able to present "the best method to do two way communication between two applications in C#". No offense. – scherand Mar 31 '10 at 18:53
  • You're right, sorry about that. I wanted to have two user clients connect to each other and exchange information. I would have liked to avoid having a standalone server application, but if I have to then obviously I would. My intentions were over the internet on different machines. No offense taken, what I meant by the question was a "simple way", not necessarily the "best way"-like I said, I'm new to C# and wanted to try to keep it as beginner-ish as possible. – IronManIngellis Mar 31 '10 at 22:56

4 Answers4

4

WCF (Windows Communication Foundation) is what you want.

Jaxidian
  • 13,081
  • 8
  • 83
  • 125
  • 1
    Remoting is one possible option within WCF but there are others as well without changing a single line of code, just a config file. – Jaxidian Mar 31 '10 at 18:50
1

You have several options:

  1. Using pipes
  2. Using sockets
  3. WCF
Giorgi
  • 30,270
  • 13
  • 89
  • 125
0

You're needing .NET Remoting.

Remoting can be between two apps on the same computer, or across a network.

Here is a good start, the first link is a "Hello World!" remoting application: http://msdn.microsoft.com/en-us/library/kwdt6w2k%28VS.71%29.aspx

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • 3
    .NET Remoting has been deprecated in favor of WCF. Please do not direct new people at .NET Remoting. – John Saunders Mar 31 '10 at 18:51
  • I'd have to take issue with the idea that .NET Remoting has been "deprecated" in favor of WCF. Does this mean Microsoft will no longer support my code if I'm using TCP or pipes? Hardly. Additionally, follow the link in my answer. If there was a question of deprecation, the content behind that link would say something to that effect. Microsoft may favor WCF over Remoting as a general rule, but that marketing issue does not make my answer incorrect. – Dave Swersky Mar 31 '10 at 19:03
  • 3
    your link is the .NET 1.1 link. Please don't post those except in answer to .NET 1.1 questions. The current link is http://msdn.microsoft.com/en-us/library/kwdt6w2k.aspx, which says, "This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the Windows Communication Foundation (WCF). Link=http://go.microsoft.com/fwlink/?LinkID=127777" – John Saunders Mar 31 '10 at 20:44
0

I would also take a look at NServiceBus. It's really easy to setup and provides you with a reliable messaging system. Any messages sent between the apps (whether the destination app is online or not) are always delivered. The library leverages MSMQ to facilitate communication.

Rohland
  • 1,405
  • 14
  • 20