| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
-Joshua
On Apr 2, 2007, at 10:46 PM, Greg Guerin wrote:
Joshua Smith wrote:
I'm looking at integrating with a package which expects to run in its own process, and communicate with callers via sockets. Their C- oriented documentation recommends creating the communications endpoints using socketpair. These are two-way communications channels: I send messages down my side of the pair, and then read from that same file descriptor to get the return code. (I pass the FD of their end as an integer on the command line.)
Unlike most BSD socket functions, there appears to be no socketpair in the java.net.Socket interface. I found something called a Pipe in java.nio, which I think creates a one-way socket (like a unix pipe).
I'm sure the socketpair function must be wrapped in some Java API, right? Can one of you geniuses point me at it?
The features you want aren't directly exposed by anything in a typical Java
installation, AFAIK.
I strongly doubt that Java's Pipe class will do anything for you, mainly
because it's not inter-process.
I'm not sure about this, but if you have to pass an FD as an arg, maybe you
want the java.io.FileDescriptor class. You'd still have to set up the
connection using ServerSocket and Socket, then dig into the FileDescriptor
object from the Socket (i.e. endpoint) you want to pass to the other
process. You'd have to use reflection, since the mebers are private.
Even then, I'm not sure this will work, because the fd's may be closed when
you Runtime.exec() the other process (Runtime.exec() is technically a
fork()/execve() in Unix terms). Java is not conducive to passing
already-open fd's to child processes. It wasn't intended to be, because
the internals of sockets are OS-specific.
If the other process is expecting a connection on a Unix-domain socket,
there isn't any simple or easy way to make that connection. If you have to
use Unix-domain sockets, all I know of is the Jtux library, mentioned here:
<http://lists.apple.com/archives/java-dev/2006/Dec/msg00167.html>
I'm not sure Jtux would work, either, because of Runtime.exec() constraints.
It might help if we knew which package you're using that expects to run in
its own process with a passed-in fd arg. You might have to write a native
wrapper app of some kind, but I'm just guessing.
-- GG
_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden
_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden
| References: | |
| >Re: socketpair equivalent? (From: Greg Guerin <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.