Possible Duplicate:
Can C# be piped?
Is there a way to connect two programs across a network in such a way that all calls coming from the one program can be piped across to another computer and then given to the receiving program. I’ve included one way that I could do this below, but there should be a better way, since this is would be a ponderous (and seemingly pointless) amount of code to keep up-to-date. The program I am working with is Ascom, which uses a lot of inter-process communication with COM. This is just an example, there are many interfaces that would need to be kept 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 that would 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 just simply take the server interface, and pipe it across to the client, and take the client interface and pipe it across to the server, as illustrated below? That way the server would call the pipe and the pipe would forward it to the client. If the client would call the server, it would simply forward it to the server. Since we are dealing with separate programs, that should be very simple I would think. I was reading about .NET Remoting, but that is apparently deprecated. I asked this question before, but no one answered so I thought I would spell out //exactly// what I am triying to do.
Client ====(<Server) Pipe (Client>)==== Server
When I say pipe, I just mean a connection that sends data from one program to another across the network. Also, I am looking for either an example implementation, or a link to an example implementation. Not just “try x or y”. This has to be possible!
In short what I am trying to do is make so that the client and the server can communicate as if they are on the same computer, where they are using COM, without having the “man in the middle” translate anything, just connect them.
The objectives your question sets out are a little hard to disseminate, but as I understand it, you’re looking for a mechanism for communicating between clients and servers over a network.
If this is the case, the Windows Communication Foundation (WCF) should be your tool.
It works on the basis of creating a contract between server and client, defined as a .NET interface (with some caveats), which can then be exposed via a server (using a range of protocols) and consumed by a client application.
You can follow this article to get a quick start into the technology; it should give you enough information to create a prototype to see if it meets your needs.
The subject of WCF is quite massive though, so you’ll need to spend time with it to get it working exactly as you’d like.
If your processes are running on the same box, you can used Named Pipes to perform cross-process communication (
<netNamedPipeBinding>), as a replacement for COM. Named Pipes are designed specifically for cross-process communication and very efficient at this task.If your processes are running on different boxes, you can use TCP to perform the same communications over a network (
<netTcpBinding>). TCP will communicate in binary messages, so is still very effective for communicating between your two processes.As far as WCF is concerned, these are just configuration settings. Once you have set up your server and client, you can communicate over the network as easily as if the two applications were on the same box.