As btrott said, unless you are using some very specific preexisting
class in your Java program, I don't think there is anything you
could not do in Perl with respect to networking. So why not
do the whole thing in Perl?
But if you really need to split it between the two, one simple
way of passing things between a Java and a Perl program would be
to use pipes. Assuming you are on Unix, that is.
If the perl program gets executed first, you could create a couple
of pipes, fork a child process and execute the Java program there.
Then the Java program can read from STDIN and write to STDOUT
to communicate with your perl program. Something like this:
pipe RDRPARENT, WRTCHILD or die "Error: $!\n";
pipe RDRCHILD, WRTPARENT or die "Error: $!\n";
if (defined($pid=fork)) {
if ($pid) {
# In the parent
# Close child's ends of the pipes
close(WRTCHILD); close(RDRCHILD);
# Continue, reading from RDRPARENT and writing to
# WRTPARENT to communicate with the Java program.
} else {
# In the child
# Close parent's ends of the pipe
close(WRTPARENT); close(RDRPARENT);
# Redirect STDOUT and STDIN to the pipes.
open(STDOUT, ">&WRTCHILD") or die "Error: $!\n";
open(STDIN, "<&RDRCHILD") or die "Error: $!\n";
# Execute the java program
exec("java prog.class");
die "Exec error: $!\n";
}
} else {
die "Fork error: $!\n";
}
Something similar could be done if the Java program is the one
that gets executed first, but my Java is too rusty to make
an attempt at that.
--ZZamboni
|