For a project of mine, I have been using Java RMI to separate my client and server. Now RMI is really cool to transport Java objects for communication, but I have been wondering if I can transport file over RMI. Now I know we can start a flame war over RMI as a file transport medium and I know very well that I can use FTP, SCP, SSH, HTTP and you name it, but I wanted to use something easy short and which fits into my application seamlessly.
To solve this problem I decided to find out how I can actually transport a file over RMI. Small files are not really a problem, just load them in as a byte array and then serialize them over RMI, but you don’t really want to transport multi megabyte files in this way. The larger the file gets, the larger the memory needed just for transportation so I just decided I’d build a session and then transport the file in chunks.
While googling for a solution I came across a few other people trying this, so I decided I’d just blog about it and post my code as well. If someone can use it, then that makes me happy =))
Easy to use:
- Untar to a folder
- run “compile.sh”
- run “runserver.sh 192.168.1.1” on the server
- edit “config.xml” on the client and set the address and the other options
- run “runclient.sh serve.txt” on the client and you will get the test file “serve.txt”
Update: fixed link to file