问题
I found out that there is a .Net toolkit called GCT - Group Communication Toolkit that is the C# version of JGroup. I want to know whether this and JGroup can be connected together to make java and C# clients communicate with each other. If not, what would be the best option to make a java program and a C# program communicate? One other option I came across is XMPP implementation. I require very fast message passing between those two programs that are running in the same computer. The main requirement is that either of this program would send a message to the other, when some particular events are triggered. any ideas are welcome.
回答1:
XMPP isn't what you want. It's designed for passing messages between computers with a central server.
I'd recommend using sockets to pass data between the apps. See the System.Net.Sockets.Socket class in C# and the java.net.Socket class in Java.
回答2:
Where I work we use ICE (http://www.zeroc.com/). It lets us marshal binary data between java and C#. It's not bad.
回答3:
Google's Protocol Buffers might be a option. It's very portable and quite fast.
回答4:
Responding to the OP's "answer" ...
The way to map "server push" onto the classical RPC model (e.g. as implemented by CORBA, SOAP, ICE, RMI, and so on) is to flip the role so that the thing you think of as your server fills the client role in the RPC. The pattern is like this:
Your client makes a call to your server, passing the handle for a callback object.
The server remembers the callback object and returns.
The client goes to sleep (or does something else ...)
Later on, the server wants to push some data.
The server invokes the "push" RPC on the callback object, passing the data.
The client receives the call/request on the callback object, does something with the data, and replies.
回答5:
If I were doing this, and needed low-latency, I might consider a memory-mapped file, or a pipe. Either of these would require some JNI and p/invoke programming.
回答6:
If performance is important, see what's used in scientific computing. Scientists have the same sort of problems seen in enterprises, needing to connect clients and servers and all that, in an even wider range of languages and platforms. Perhaps this component tie-together tool called Babel would be useful beyond its original domain? Interfaces are described by SIDL (like IDL in CORBA) but I don't know if C# is covered yet. https://computation.llnl.gov/casc/components/babel.html
来源:https://stackoverflow.com/questions/1719935/communication-between-java-and-c-sharp