This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

input from process invoked via RMI  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i'm writing a client-server application using RMI. the client presses a button which invokes a remote method which creates a process on the server side using Runtime.exec(). now i need to get the output from the process (standard output) and send it back to the client while it's being written. the idea is to keep the client updated on the process status.

any ideas...i don't think serializing an InputStream will work...right?

by the way, i'm relatively new at Java.

thank you!
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, an InputStream isn't serialiazable, but the data inside it is. Assuming that the data being returned from your Process is character data, you can wrap the InputStream in an InputStreamReader, the a BufferedReader, and use readLine() to get the output from the process as a series of Strings. You could also just read byte[]s directly from the InputStream and return those, too, but I'm assuming it's going to be turned into Strings sooner or later.

Another idea to keep in mind is the length of time it takes for the process to execute... do you want to call one method and get the results as a return value after it's finished? Or do you want to make an interface for the client to send to the server, and have the server send pieces of data to the client when they are available?
 
Bartender
Posts: 19449
88
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it sounds like you want a progress callback. I use one in a process that can span literally days. It's defined as an interface that gets implemented in one of the remote client classes.

There's some pretty decent docs on RMI callbacks, but I forget where. I just googled for them when I needed them.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!