Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

how to call a c function from my java program?

Thread view: 
manoharyes@gmail.com - 29 May 2006 09:27 GMT
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.
Gordon Beaton - 29 May 2006 09:38 GMT
> 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

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Thomas Weidenfeller - 29 May 2006 09:44 GMT
> 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
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Bjorn Abelli - 29 May 2006 09:48 GMT
<manoharyes@gmail.com> wrote...

> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.