Solved

Applet spawning a separate Java application ?

Posted on 1997-04-24
3
436 Views
Last Modified: 2013-12-29
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

0
Comment
Question by:dgason
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
pedxing earned 100 total points
ID: 1219826
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
 

Expert Comment

by:pedxing
ID: 1219827
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
 

Author Comment

by:dgason
ID: 1219828
Hi!

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

Dave
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 104
maven module vs maven project 3 112
Crystal Reports Licensing Questions 4 83
using executorService 3 18
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question