aspose file tools*
The moose likes Distributed Java and the fly likes Serializing a file over RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Serializing a file over RMI" Watch "Serializing a file over RMI" New topic
Author

Serializing a file over RMI

Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
I have a functioning RMI application, and I have decided that I want the client to be able to send a 1GB file to the server. Obviously, as this is RMI, I can't just pass in a FileInputStream to my remote method call. Also, I can't read the whole file in to a bytearray and send that over, since the file is too big to fit in memory.

What's the best way (or any way) to do this, then? I assume that there's some standard way to do this, but I haven't been able to figure it out.

Thanks for any suggestions and advice
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

As you've found - RMI isn't a great way to send files full of data - so why do you want to only use RMI to do this? One good approach is to have the server respond to the client with *where* it can get the file (as a URL), and then have the client use FTP or some other protocol to download the file.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
The client is sending the file to the server, not vice-versa....

My client app runs on a user's desktop and performs all operations against the server via RMI. The client has no HTTP or FTP server running, and user requirements specify that this will not change. Can I open a socket or something? There's got to be a way to do this - I can't be the only person who's wanted to send a file from a client to a server.....
[ August 15, 2005: Message edited by: Tom McAmmond ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Oops... sorry, didn't notice that the file was coming from the client until you pointed it out...

Hmmm... not sure if there's a "standard" or "common" way of going about this...

You wouldn't necessarily need a FTP server running on the client to use FTP - you could have an FTP server running on the server and use the FTP protocol to send the files from the client.

This would probably require you to dig a bit into FTP protocol internals.

You could also definitely use straight sockets to do this, too - something like -

1.) Have the client call a server RMI method that returns an IP and port to send the file to.
2.) The server start up a ServerSocket and return it's IP and port to the client.
3.) The client then opens a socket using the data supplied, opens an output stream to the file (hopefully wrapped in a buffered stream, and maybe even using a gzipped stream to speed things up) and stream the file data across the socket.

Hopefully this helps you figure a good approach out...
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

I am writing this so that anyone need help in this regard is guided,

There is RMIIO that is helpful in this regard.

http://openhms.sourceforge.net/rmiio/

Thanks,

Maki Jav


Help gets you when you need it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializing a file over RMI