How to send a string from one program to another?

Is there a way to send a (small) string from one program to another assuming that both programs are on the same PC   

I have tried using a tcp client and server connection between the two programs.  This works, but I was wondering if there was a more efficient way to do this.

Thanks for any ideas,
MisterT
 


Answer this question

How to send a string from one program to another?

  • HonFui

    An XML Web Service would be overkill, since it requires the overhead of an HTTP server like Internet Information Server.

    .NET Remoting is the de facto inter-domain communication technology and up until .NET 2.0 I would've recommended using a TcpChannel to communicate between processes on the same PC instead of the HttpChannel. Both of these channels - known as transport channels because they are responsible for transporting the data - were defined in the base class library.

    .NET 2.0 adds the new IpcChannel, which uses the IPC system in Windows and is much faster than TCP and even more faster than HTTP. Read about the System.Runtime.Remoting.Channels.Ipc namespace for details.

    The documentation for the IpcChannel class includes a sample - in either Managed C++ or J# - of both the client, server, and remote object. In your scenario, the remote object would be some System.MarshalByRefObject derivative in application B while application A (assuming A wants to pass a string to B) instantiates a remote instance of that object and calls a method on it passing the string.

    You should read Accessing Objects in Other Application Domains Using .NET Remoting in the .NET Framework SDK. This gives you an overview and examples of .NET Remoting objects.

    The advantage of .NET Remoting is that a system of format sinks (SOAP, binary, and third-party classes) and transmission sinks (IPC, TCP, HTTP, and third-party classes) is already defined. You need only define the remoting objects (objects you communicate with remotely, be that in different AppDomains in the same process, different processes on the same machine, or even different processes on different machines) and the types to pass "over the wire" (the transmission sink, or channel). There are some restriction which the article above will discuss, like that the objects to pass must be serializable.

  • barnefr

    Hello Heath,

    Thank you very much for your excellent reply.  I will give .NET remoting a try.

    Regards,
    Mister T

  • _Phil_

    Use System.Messaging namespace.

    One app creates a queue or both and use can send object to each queue. Just think in real world terms. The Message object under System.Messaging is a letter and the queue is the letter box. The Windows OS comes with Message Queuing which will deliver the letter to the approriate queue (letter box). To install Message Queuing go to Add/Remove windows components. There is plently of documentation about the namespace. Good thing about it is that it works and there's not many lines of code to write.

  • kqjf

    I would say there are much simpler ways of doing this. One of the approach would be to use a Webservice. The other option would be to use .NET Remoting.

    Links:
    Web Services:
    http://www.codeproject.com/dotnet/intro2websvc.asp
    http://www.mastercsharp.com/article.aspx ArticleID=52&&TopicID=7

    .NET Remoting:
    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/hawkremoting.asp

    Regards,
    Vikram

  • Farmer Bob

    However, in terms of developer learning curve and real world implementation situation, Webservices are much easier to develop and faster to implement as compared to a .NET Remoting based solution - so you might want to consider how much performance you really need and how much time you have to deliver the solution as well.

    That said, yes, IIS would be an additional requirement for Web Services based solution.

    And go through this link as well:
    http://blogs.msdn.com/richardt/archive/2004/03/05/84771.aspx

    Regards,
    Vikram



  • MikeC#

    Paul, the big issue there is that you are potentially - nay, most likely - overwriting something in the clipboard the user put there for a reason. They may not appreciate it being overwritten. I wouldn't recommend using the clipboard for inter-process communication.



  • Murray Sobol

    Web Services won't help you send a string from one process to another process (besides aspnet_wp.exe for < IIS6 or w3wp.exe for IIS6) without the Web Service itself communicating with another process.

    If "Mister T" already has two processes and because Web Services can't callback like .NET Remoting can through either the TcpChannel, IpcChannel, or some third-party channels, "subscribing" two different processes to the Web Service won't do any good.

    To communicate between two processes you need to use either .NET Remoting or make your own serialization and transmission system like using a socket connection, which is what he said he did (or considered) before. That's entirely possible to do - along with your own IPC implementation using named pipes, DDE, etc. - but .NET Remoting encapsulates all that's required and adds a lot more flexibility in its support for sink chains.



  • Calo

    Hi,

    A simple and fast workaround on this, assuming that its on the same PC and its a string, is by using the clipboard. You could place a string data in a clipboard and letting the other program get the value on the clipboard. You must do this very fast, coz you'll never know when a user uses the clipboard. I know its quite lame but you could give it a try...

     

    cheers,

    Paul June A. Domag



  • Yoseph

    I needed to do the same thing and found the following article on code guru, have a read it might help you as well.

    http://www.codeguru.com/Csharp/Csharp/cs_network/remoting/article.php/c10199

    Mykre
    www.ircomm.net
    Managed DirectX and Game Programming Resources

  • How to send a string from one program to another?