Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to send a file using RMI

843793Oct 7 2006 — edited Feb 8 2010
hello,,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 8 2010
Added on Oct 7 2006
20 comments
3,759 views