how to send a file using RMI
843793Oct 7 2006 — edited Feb 8 2010hello,,
I do one program using RMI that shoud transfer a file.. I compiles and no errors .while i am trying to execute this program i found some exception .
rmiUnmarshalling exception and writeAborted Exception.
////Server.java
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class Server extends UnicastRemoteObject implements serverInterface
{
private InputStream in;
String filename;
public Server(String filename) throws RemoteException
{
this.filename = filename;
}
public InputStream send() throws RemoteException
{
try
{
in = new FileInputStream(filename);
int c;
while((c = in.read()) != -1)
System.out.println((char)c);
}
catch(Exception ex)
{
System.out.println("Exception in impl : "+ex);
}
return in;
}
public static void main(String arg[])
{
try
{
Naming.rebind("Server" , new Server("E:\\muthukumar\\RMI\\files\\interinter.java"));
System.out.println("Server is ready");
}
catch(Exception e)
{
System.out.println("Exception in server : "+e);
}
}
}
/// serverInterface.java
import java.rmi.*;
import java.io.*;
public interface serverInterface extends Remote
{
public InputStream send() throws RemoteException;
}
///Client.java
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
class Client
{
public static void main(String arg[])
{
try
{
serverInterface inter= (serverInterface)Naming.lookup("//localhost/Server");
InputStream in = inter.send();
int c;
while((c = in.read()) != -1)
System.out.println((char)c);
}
catch(Exception e)
{
System.out.println("Exception in client : "+e);
}
}
}
please help me...
thanks in advance..
regards,
Muthukumar