• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

C++ to Java

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem.

I want a C app to send messages to my java app.

I know the JNI allows C to talk to Java, is the way to do it, to create a DLL, pass in a java class when my java app starts up and then let the C app talk to the DLL which will call my java class, which in turn will call my java app?

Thanks in advance for any advice.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can send messages through a port.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mr. C Lamont Gilbert:
You can send messages through a port.



Correct, that is the best solution.

Following are (OS dependant) ways to implement IPC.
1. Shared memory
2. Named Pipes (FIFO).
3. User defined signals.

But since all of them are non-portable capabilities of OS, your JNI
wont be much portable.

So, better open sockets to send messages from C and receive it in Java app.
 
Davie Lang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replys, never thought of that!

Do you know where I could find some code examples of java C socket comms?

Thanks you.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deep Narsay:
Correct, that is the best solution.



You can't be sure of that. Communication between C code and Java code can be done by having them running in two different processes, as you suggest. But it can also be done with them running in the same process, and calling each other directly, via JNI and the Invocation Interface. Performance and architectural considerations will tell you which way to do it, for a specific application. In this case, there's been no such discussion, so the correct solution is not known.

If you do want inter-process communication, you could use CORBA. The transport happens over sockets (probably), but you save having to write the code for creating/deciphering messages. Java and CORBA play nicely together. C++ and CORBA isn't too bad.

For completeness, I should say that you could have your C and your Java code in the same process, but different threads, and they could communicate via sockets or CORBA.
[ November 03, 2005: Message edited by: Peter Chase ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic