The Artima Developer Community
Sponsored Link

Java Answers Forum
Sending and running a Java program on a remote computer

19 replies on 2 pages. Most recent reply: Jul 31, 2005 5:41 PM by MS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 19 replies on 2 pages [ 1 2 | » ]
MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Sending and running a Java program on a remote computer Posted: Jun 14, 2005 2:07 PM
Reply to this message Reply
Advertisement
Hi!

I've been reading books and tutorials on this, but the closest answer I'd get from references is RMI, which is really different from what I'm looking for.

I'm looking for a way for a client computer to send a Java program to a remote server computer. The server computer then runs the program. The server cannot assume to know what the program the client will send it. It can be *any* program.

I'd appreciate some feedback/help. Thanks.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending and running a Java program on a remote computer Posted: Jun 14, 2005 10:34 PM
Reply to this message Reply
That is exactly what all those new security updates for Windows & Co try to prevent, because it's a security risk 1st grade.

If you want to do it right you need to install a listener on the server.
Send the programs to this listener, this listener is responsable to launch them.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jun 15, 2005 12:46 PM
Reply to this message Reply
Hi,

Yes, I realised that. All the server has is a server program that's ready to receive *any* java program and run it on the server machine (and possibly send some result to the client). For instance, Java applets from Web sites are sent from the Web site and run oon our computers, but it's still not necessarily considered a security issue. I just haven't a clue how:

- to make a client program send a Java file to a server.

- let the server receive the program and run it.

Thanks 4 the response; hoping to get some more help.

Thank you..

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending and running a Java program on a remote computer Posted: Jun 16, 2005 4:19 AM
Reply to this message Reply
Do you have general questions about how to implement sockets?
Then you should read the tutorials at the Sun home page.

Or don't you know how to send a file?
I've never sent a file, but you should make some kind of protocol.
1. general informations about the file, name, it's size in bytes, ...
2. then just send the file as text and let the server count the bytes, then write the content, when the size is reached.

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Sending and running a Java program on a remote computer Posted: Jun 16, 2005 8:18 AM
Reply to this message Reply
responding to MS
> I'm looking for a way for a client computer to send a Java
> program to a remote server computer. The server computer
> then runs the program. The server cannot assume to know
> what the program the client will send it. It can be *any*
> program.

I think what you are looking for is "Mobile Agent" technology.

You may look into its available implementation in java.

Some details of this yoy may find at following link

http://www.davidreilly.com/topics/software_agents/mobile_agents/index.htm

hope this helps.

regards,
Shashank

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jun 20, 2005 12:59 PM
Reply to this message Reply
Hi, sorry I was away for the week..

Thanks everyone for the responses.

I've been reading about mobile agents and I'm trying to download Voyager asap.

But I was wondering if it's possible to do what I described above using some basic socket programming (in response to an inquiry above, I do know general socket programming, so I'm not asking for a beginner's tutorial), rather than going thru the complications of mobile agents. Can't I send a Java file to a server and run it from there?

Thanks.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending and running a Java program on a remote computer Posted: Jun 21, 2005 5:08 AM
Reply to this message Reply
Yes.

But you absolutely NEED a program on the server side wich RECEIVES the file and launches it.

I'm sure there exist complete jars wich let you send and receive a file.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jun 21, 2005 8:21 AM
Reply to this message Reply
Yes.

But you absolutely NEED a program on the server side wich RECEIVES the file and launches it.

I'm sure there exist complete jars wich let you send and receive a file.


Jars? Whassat?

Yeah, I guess a program is needed to accept a TCP conxn. But how can it receive the file, then execute it? Details?

Thank-you! :-)

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending and running a Java program on a remote computer Posted: Jun 21, 2005 11:21 PM
Reply to this message Reply
You said you know how to program sockets.
And that's just how you receive the file: Through the socket.
Then you must save the Data you get from your client to the class file.
Then just start the program either by calling directly it's main method or by launchin another process (Runtime().getRuntime().exec(...))

If you don't know what jar files are you shouldn't tell me that you don't need a beginners tutorial.

What I menat was: You don't have to write everything on your own. There will surely exist some compiled code you can include in your program. Normally people put their programs in jar files instead of having hundrets of single class files on their hard discs.



About "details": I surely won't write or explain the whole program. Tell me how you would do it and where you have problems.

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Sending and running a Java program on a remote computer Posted: Jun 22, 2005 4:07 AM
Reply to this message Reply
responding to MS

> Yeah, I guess a program is needed to accept a TCP conxn.
> But how can it receive the file, then execute it?
> Details?

In most simplest form
You may find a simple program to send string to a server program using socket. And then you may pass contents of your program as string.
The server program may store that string in a file. and may use Process APIs to launch that program.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jun 22, 2005 11:40 AM
Reply to this message Reply
Thanks guys.

I'll work on it and get back if I encounter questions or problems.

I know I shouldn't be spoonfed, but I really had no idea if it can be done. I'll give this a shot...

Thnx!

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 4, 2005 1:36 PM
Reply to this message Reply
Almost done.

I've successfully sent the file to a remote computer, as well as the method name (of the class I sent) that I want the remote computer to execute in the form of a String.

But how do I now run "ClassX.methodX"?


Part of server code:
====
Socket connectionSocket = welcomeSocket.accept();
 
ObjectInputStream objStream = new ObjectInputStream(
                    connectionSocket.getInputStream());
 
File program = (File) objStream.readObject();
 
BufferedReader inFromClient = new BufferedReader(new
     InputStreamReader(connectionSocket.getInputStream()));
 
methodName = inFromClient.readLine();

---

So I'm not sure how to run the class.methodName on the server now. I tried stuff like
program.getName().methodName()
. that clearly didn't work, but it was the best I could think of.

Thanks in advance.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending and running a Java program on a remote computer Posted: Jul 4, 2005 11:01 PM
Reply to this message Reply
Start with:
Class.forName("ClassName")
.

Then you cann call any method from this class in a similar way.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 5, 2005 1:33 PM
Reply to this message Reply
Hi Matthias,

Okay, I can get the class from that, but I don't see how to run the method I want. I tried stuff like:

Class.forName(className).getDeclaredMethod(methodName, null).invoke();
but that doesn't work. Can you please be more specific?

Thank you.

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Sending and running a Java program on a remote computer Posted: Jul 5, 2005 9:44 PM
Reply to this message Reply
Look into JAVA Reflection APIs to detect dynamically the features of a class, and invoking a specific operation with arguments.

Flat View: This topic has 19 replies on 2 pages [ 1  2 | » ]
Topic: stacktrace for unchecked exceptions Previous Topic   Next Topic Topic: jdbc connectivity

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use