Applet spawning a separate Java application ?

Pedxing,
I need clarification, I put my further question in the "comments" section. After you answer this, I'll give you a really good grade. If you can't find the comment, please let me know...

I would like to have an applet spawn a separate Java process. I know how to create and use threads in Java, but I would like to have an applet spawn a completely separate application, interact with it via sockets, and then at some point kill the separate process.
I already know how to have separate processes communicate via sockets, I just don't know how to spawn a separate process and then kill it later.
Is such a thing possible in Java? It's okay if the applet and the process exist on the same machine. Sample code would be helpful (doesn't have to be elaborate)

Thanks in advance,
Dave

dgasonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pedxingCommented:
An applet cannot spawn an application on the same machine using standard security managers, as doing so would violate applet security and allow a rogue applet to have application-level control of your machine.  Not a good scenario!

I'm assuming here that your question refers to running a Java application, not another applet.  You can run multiple applets at the same time and if that is really what you want to do, let me know and I'll give you some code for that.

IF YOU ARE WILLING TO USE JDK 1.1.1

RMI (Remote Method Invocation) is the preferred method for doing this.  It requires the application to already be running (which is not precisely what you asked for).  It is also a very new API, which means that it won't be supported on a lot of browsers.  RMI programming is a big topic.  For information, take a look at:

http://www.javasoft.com:80/products/jdk/1.1/docs/guide/rmi/index.html

Pay particular attention to the tutorial, which gives you the code you were asking for.

IF YOU WANT THE APPLICATION ON THE SAME MACHINE (NO RMI):

Applet security can be relaxed in a couple of ways:

  a) replace the security manager in your browser. THIS IS DEFINITELY NOT RECOMMENDED!

  b) use a browser that allows you to configure the security options.  HotJava is the most flexible in this regard, I believe.  Again, this is a dangerous thing to do.

  c) More secure would be to use the Applet Signing system.  You can give permissions to signed applets to use system resources they wouldn't ordinarily be allowed to have.  Unfortunately, browsers which understand signed applets are in short supply right at the moment, so you lose portability.

However you get around the security restrictions, probably the easiest way to run the application would be to create a thread that had a call to java.lang.Runtime.exec().  It has the following forms:

  public class Runtime extends Object
  {
    ...
    public Process exec(String command) throws IOException;
    public Process exec(String command, String[] envp) throws IOException;
    public Process exec(String[] cmdarray) throws IOException;
    public Process exec(String[] cmdarray, String[] envp) throws IOException;
    ...
  }

IF THE APPLICATION CAN BE ON THE SERVER

Then you don't have a problem.  You can write an application that watches a particular port for messages, and a client that opens a socket to that port.  This works all the way back to JDK1.02.  Take a look at java.net.Socket.

Depending on the complexity and interactivity you wanted for the application, you could also store the application in the CGI-BIN directory and open a URL to it.  Look at java.net.URL, and possibly also java.net.URLConnection.

I hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pedxingCommented:
I'm sorry Dave, I'm afraid I can't do that.  (Sorry about that, I couldn't resist).

I don't see your comments.  You can try resubmitting them here, or email me: bruce@flair.law.ubc.ca.  I'll try to address any specific issues if I can.

And don't worry about the grade.  I'm answering your question in the hopes that someone will answer mine when I need it.  Points don't really interest me.  Thanks, though.

Bruce.
0
dgasonAuthor Commented:
Hi!

I sent you an email with my additional questions. I hope that you can find a good answer!

Dave
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.