Click to See Complete Forum and Search --> : How to integrate Java programs with other programs in other languages ?
Yves M
January 15th, 2003, 07:42 AM
Hi,
We are trying to develop a simple Code War (http://www.codeguru.com/forum/showthread.php?s=&threadid=226158) program that will allow client programs in different programming languages to compete with each other. We would like to support Java as well as C++, VB and C#. As my knowledge of Java is pretty limited, I'd like to ask you which method would work best (work at all ?) for communicating. The server will be written in C++, but that shouldn't matter.
The options I have come up with so far are:
DLL-based approach with exported functions. As far as I understand Java, it's impossible to do this, right ?
COM-based approach. I would guess that Java could use COM on Windows platforms, but I might be wrong.
TCP/IP. This is the only other option that I could come up with. I know it would work in Java, but would be a real pain in the other programming languages.
I'm thankful for any suggestions and ideas. If you would like to help in coding, just visit the forum Code War (http://www.codeguru.com/forum/forumdisplay.php?s=&forumid=50)
Goodz13
January 15th, 2003, 08:16 AM
DLL-based approach with exported functions. As far as I understand Java, it's impossible to do this, right ?
You can use DLL's with Java via the JNI (Java Native Interface). Basically you include JNI.h in your C/C++ DLL and there you go. There is a little more to it, but yes it is possible.
COM-based approach. I would guess that Java could use COM on Windows platforms, but I might be wrong.
Not sure on this one. Maybe dlorde might be a little more help here.
TCP/IP. This is the only other option that I could come up with. I know it would work in Java, but would be a real pain in the other programming languages.
I've never actually used the JNI approach before, but I have used TCP/IP to communicate with Java and VB.
Yves M
January 15th, 2003, 08:27 AM
Originally posted by Goodz13
You can use DLL's with Java via the JNI (Java Native Interface). Basically you include JNI.h in your C/C++ DLL and there you go. There is a little more to it, but yes it is possible.
What I want is to call Java functions from C++, and C++ functions from Java. So this is possible with a simple DLL approach ?
Actually the COM thing is better, since VB handles COM easily, but not straight DLLs
Goodz13
January 15th, 2003, 08:43 AM
Unfortunatly I have little experience with JNI in java, but I'll research it a bit more.
I'll also look up Java and COM.
dlorde
January 15th, 2003, 08:54 AM
> Maybe dlorde might be a little more help here.
Sorry, my COM days were long-ago, before I got into Java...
I'm not really sure what the problem is. Why do you need to call C++ functions from Java and vice-versa? what about the other languages?
If each client runs a local language application that competes with other clients via the C++ server, why not use the server to supply any common processing facilities that all clients need?
For example, Web Services (e.g. .NET) would allow the server to supply common processing facilities to each client on request, alternatively you could devise your own game protocol using a simple communications interface, such as RPC or sockets.
All that is needed for evil to triumph is for good men to do nothing...
Yves M
January 15th, 2003, 09:37 AM
Originally posted by dlorde
I'm not really sure what the problem is. Why do you need to call C++ functions from Java and vice-versa? what about the other languages?
I'm basically looking for a way to handle communication between different languages as easily as possible. "call a C++ function" just means that the java program should be able to initiate a communication with the C++ server, send it some data and get feedback.
If each client runs a local language application that competes with other clients via the C++ server, why not use the server to supply any common processing facilities that all clients need?
If possible, I'd like to use a common interface for all languages. If Java communicates with web services, VB communicates via COM and C++ communicates as a DLL then writing the server is going to be a mess.
For example, Web Services (e.g. .NET) would allow the server to supply common processing facilities to each client on request, alternatively you could devise your own game protocol using a simple communications interface, such as RPC or sockets.
Yes, maybe sockets are the easiest way. The solution defaults to this one if there is no possibility in Java to use local COM objects and create some of its own.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.