how to call a c function from my java program?

M

manoharyes

hi experts,
i am trying to build an application which requires a java and c
interconnection.
the applet has a textarea and it stores the contents entered in the
textarea in a file.
My c function, reads the content of the file and constructs a datagram
sends it to a System with a specified IP.. i am using linux
environment..
can i do this?
please help me..
thanking u in advance..
Xoinki.
 
G

Gordon Beaton

i am trying to build an application which requires a java and c
interconnection. the applet has a textarea and it stores the
contents entered in the textarea in a file.

Which: an application, or an applet?
My c function, reads the content of the file and constructs a
datagram sends it to a System with a specified IP.. i am using linux
environment.. can i do this?

You can use JNI to call C methods that have been written specifically
to be called from Java (i.e. you cannot call arbitrary C functions
directly, but since you can call them from your C methods this is not
usually a problem).

There is however nothing in your description of the C function that
can't be done directly in Java.

/gordon
 
T

Thomas Weidenfeller

hi experts,
i am trying to build an application which requires a java and c
interconnection.
the applet

Applet? If it is an applet, it requires some extra effort (signing) to
get access to C functions.
My c function, reads the content of the file and constructs a datagram
sends it to a System with a specified IP.

Why not doing this in Java, too?
can i do this?

Check out JNI.

/Thomas
 
B

Bjorn Abelli

i am trying to build an application which requires
a java and c interconnection.

Which is possible through JNI.

http://mindprod.com/jgloss/jni.html
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html

But maybe you're not really talking about "interconnectivity"?
the applet has a textarea and it stores the contents
entered in the textarea in a file.

Just write it to a textfile, in a format of your choice...
My c function, reads
the content of the file and constructs a datagram
sends it to a System with a specified IP..

....read the file and parse the content. You have defined the format
yourself, so that wouldn't be any problem.

But where does the "interconnectivity" come in?

If you want to use *real* interconnectivity, you should use JNI in order to
call the function written in C directly from the Java GUI. No need to save
it to a file in between... ;-)

/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top