Connecting two programs over the network using .NET.

Possible duplicate:
Is it possible to pass C #?

Is there a way to connect two programs over the network so that all calls coming from one program can be transferred to another computer and then transferred to the receiving program. I have included one of the ways that I could do this below, but there should be a better way, since it will be heavy (and seemingly senseless) code to keep abreast of the latest developments. The program I'm working with is Ascom, which uses a lot of interprocess communication with COM. This is just an example; there are many interfaces that will need to be updated.

class SwitchConverter : ASCOM.Interface.ISwitch { private Client client = new Client(); private string query(string query){ return client.query(query); } private void send(string command) { client.send(command); } public bool Connected { get { return bool.Parse(query("SWITCHGETCONN")); } set { send("SWITCHSETCONN:" + value); } } public string Description { get { return query("SWITCHGETDESC"); } } public string DriverInfo { get { return query("SWITCHGETDRVI"); } } public string DriverVersion { get { return query("SWITCHGETDRVV"); } } public bool GetSwitch(short ID) { return bool.Parse(query("SWITCHGETSTAT:" + ID)); } public string GetSwitchName(short ID) { return query("SWITCHGETNAME:" + ID); } public short InterfaceVersion { get { return short.Parse(query("SWITCHGETINTV")); } } public short MaxSwitch { get { return short.Parse(query("SWITCHGETMAXS")); } } public string Name { get { return query("SWITCHGETNAME"); } } public void SetSwitch(short ID, bool State) { send("SWITCHSETSTAT:" + ID + "-" + State); } public void SetSwitchName(short ID, string Name) { send("SWITCHSETNAME:" + ID + "-" + Name); } public void SetupDialog() { throw new NotImplementedException(); } } 

So, as you can see, it will look like this:

  /== Encoder ==\ /== Decoder ==\ /=== Encoder ===\ /=== Decoder ===\ /==== Encoder ====\ /==== Decoder ====\ Client ==<===== Encoder =====>== Pipe ==<===== Decoder =====>== Server \==== Encoder ====/ \==== Decoder ====/ \=== Encoder ===/ \=== Decoder ===/ \== Encoder ==/ \== Decoder ==/ 

Now, is there a way to simply take the server interface and pass it to the client, and take the client interface and pass it to the server, as shown below? Thus, the server will call the receiver, and the pipe will forward it to the client. If the client calls the server, it simply redirects it to the server. Since we are dealing with individual programs, this should be very simple, I would think. I read about .NET Remoting, but this is clearly not recommended. I used to ask this question, but no one answered, so I thought I would tell // exactly // what I'm doing.

 Client ====(<Server) Pipe (Client>)==== Server 

When I say pipe, I mean a connection that sends data from one program to another over the network. In addition, I am looking for either an implementation example or a link to an implementation example. Don't just try x or y. It should be possible!

In short, I'm trying to make the client and server communicate as if they were on the same computer, where they use COM, without having a โ€œman in the middleโ€, something translates, just connect them.

+4
source share
1 answer

The goals set by your question are a little difficult to distribute, but, as I understand it, you are looking for a mechanism for exchanging data between clients and servers over the network.

If so, the Windows Communication Foundation (WCF) should be your tool.

It works on the basis of creating a contract between the server and the client, which is defined as the .NET interface (with some reservations), which can then be opened through the server (using a number of protocols) and consumed by the client application.

You can follow this article to quickly start using this technology; He should provide you with enough information to create a prototype to see if it fits your needs.

The WCF theme is quite massive, so you will need to spend time with it so that it works exactly as you would like.


If your processes are running in the same field, you can use Named Pipes to perform interprocess communication ( <netNamedPipeBinding> ), as a replacement for COM . Named pipes are designed specifically for interprocess communication and are very effective in this task.

If your processes are running in different blocks, you can use TCP to perform the same network connection ( <netTcpBinding> ). TCP will communicate in binary messages, so it is still very efficient for exchanging data between two processes.

As for WCF, these are just configuration settings . Once you have configured your server and client, you can communicate over the network as easily as if both applications were in the same window.

+4
source

Source: https://habr.com/ru/post/1400420/


All Articles