Search code examples
javac#file-uploadasyncsocketmessage-passing

Passing data between C# and Java Apps


I have an API in C# .Net for uploading files whose size vary between 10 B - 100 KB. Per second, the system receives around 5 such calls. Now I want to pass this file to a JAVA process (Because it is a producer of Kafka, and we want it to be JVM based, while C# API is legacy). Both are going to reside on the same machine almost always. What is the best way of doing that?

I read about jni4net, IKVM for interacting with Java from C#. Would they be better or should I make it socket based (Web API in Java accepting the files), or should I read from the local filesystem where C# App has uploaded or any other option that I am missing?


Solution

  • In environment with high concurrency, reading from the local file-system might not be good idea.

    You could use memory mapped files which java supports with FileChannel.

    Depending on operating system, you could also use Named pipes for IPC, here is an article showing how to use pipes between .Net and Java:

    http://v01ver-howto.blogspot.com/2010/04/howto-use-named-pipes-to-communicate.html

    All options considered, i would go with sockets. They are portable and easy to do and will most likely meet performance requirements you have.