Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.*;
- import java.util.Vector;
- public interface HelloInterface extends Remote {
- boolean login(String name, String password)throws RemoteException;
- boolean saveText(String text, String access, String user)throws RemoteException;
- Vector<Text> viewTexts(String user)throws RemoteException;
- }
- import java.net.*;
- import java.rmi.*;
- public class HelloServer {
- public static void main(String args[]) {
- try {
- HelloServerImplementation helloServer = new HelloServerImplementation();
- Naming.rebind("HelloServer", helloServer);
- }
- catch(Exception e) {
- System.out.println("Exception: " + e);
- }
- }
- }
- import java.rmi.*;
- import java.rmi.server.*;
- import java.rmi.registry.*;
- import java.net.MalformedURLException;
- import java.util.Vector;
- class Text{
- String text;
- String access;
- String user;
- Text(String text, String access, String user){
- this.text = text;
- this.access = access;
- this.user = user;
- }
- }
- public class HelloServerImplementation extends UnicastRemoteObject implements HelloInterface {
- static Vector<Text> v = new Vector<Text>();
- public HelloServerImplementation()throws RemoteException
- {
- for(int i = 0; i<10; i++){
- v.add(i, new Text("This is Text No. "+i, "public", "root"));
- }
- }
- public boolean login(String u, String pass)throws RemoteException
- {
- if(u.equals("shail")&&pass.equals("password"))
- return true;
- else return false;
- }
- public boolean saveText(String text, String access, String user)throws RemoteException{
- v.add(new Text(text, access, user));
- return true;
- }
- public Vector<Text> viewTexts(String user)throws RemoteException{
- Vector<Text> send = new Vector<Text>();
- for(int i = 0; i<v.size(); i++)
- if(v.elementAt(i).access.equals("public")||v.elementAt(i).user.equals(user))
- send.add(v.elementAt(i));
- return send;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement