PROGRAM: (SERVER)
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.sql.*;
import java.io.*;
class buff implements Serializable
{
public byte b[];
}
interface trans extends Remote
{
public buff get(String s) throws
RemoteException;
}
public class fileTrans extends
UnicastRemoteObject implements trans
{
fileTrans()throws RemoteException
{ }
public
buff get(String s) throws RemoteException
{
buff
o=new buff();
try
{
System.out.println(s);
FileInputStream o1=new FileInputStream(s);
o.b=new
byte[o1.available()];
o1.read(o.b);
System.out.write(o.b);
o1.close();
}
catch(Exception
e)
{
System.out.println(e);
}
return o;
}
public static void main(String[] x)throws
Exception
{
fileTrans
tt=new fileTrans();
Naming.rebind("file",tt);
}
}
PROGRAM: (CLIENT)
import java.rmi.*;
import java.rmi.registry.*;
import
java.io.*;
interface trans extends Remote
{
public buff get(String s) throws
RemoteException;
}
class getfile
{
getfile()
{
try
{
trans
m1=(trans)Naming.lookup("rmi://Localhost/file");
String
s="chord.wav";
buff o=m1.get(s);
FileOutputStream
fo=new FileOutputStream("ch.wav");
fo.write(o.b);
}
catch(Exception
e)
{
System.out.println(e);
}
}
public static void main(String[] a)
{
getfile
o=new getfile();
}
}
No comments:
Post a Comment
Thanks for your valuable comments