Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Practical No.1
- Aim: Write a program that implements the concept for sharing resources using distributed system
- Output:
- 1.Checking if Samba is installed:
- 2.Change to home directory:
- 3.Configuration file:
- 4.Starting Samba:
- 5.Starting on boot time:
- 6.Stopping and checking status of firewall:
- 7.Setting and getting settings:
- 8.Enabling:
- 9.Adding user and setting password:
- 10.Setting password for user:
- 11.Start Samba:
- 12.Restarting Samba:
- Practical No.2
- Aim: Write a program for implementing Client Server communication model.
- Practical 2A: A client server based program using TCP to find factorial of the number.
- Code:
- 1.Factorial Server
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- classFactorialServer
- {
- public static void main(String[] args)
- {
- System.out.println ("TCP Factorial Server"); try
- {
- ServerSocketss=new ServerSocket(4000);
- Socket s= ss.accept();
- DataInputStream dis =new DataInputStream (s.getInputStream());
- DataOutputStream dos =new DataOutputStream (s.getOutputStream());
- intnum= dis.readInt();
- int fact = 1;
- for (int i =1; i<=num ; i++)
- {
- fact=fact *i;
- }
- dos.writeInt(fact); s.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output:
- 2.FactorialCllient
- import java.io.*;
- import java.net.*;
- classFactorialClient
- {
- public static void main(String[] a)
- {
- System.out.println ("TCP Factorial Client") String host = "localhost";
- int port =4000;
- try
- {
- System.out.println("Enter the number whose factorial is to be found");
- DataInputStream in= new DataInputStream(System.in);
- intnum =Integer.parseInt(in.readLine());
- Socket s = new Socket (host , port);
- DataInputStream dis = new DataInputStream(s.getInputStream());
- DataOutputStream dos= new
- DataOutputStream(s.getOutputStream());
- dos.writeInt (num);
- int i = dis.readInt();
- System.out.println ("Factorial of the number :"+i); s.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output:
- Practical 2B: A client server based program using TCP to add given numbers.
- 1.TCPAddServer Code:
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- classTCPAddServer
- {
- public static void main(String[] a)
- {
- System.out.println ("TCP Factorial Server")
- try
- {
- ServerSocketss=new ServerSocket(4000);
- Socket s= ss.accept();
- DataInputStream dis1 =new DataInputStream (s.getInputStream());
- DataInputStream dis2 =new DataInputStream (s.getInputStream());
- int num1= dis1.readInt();
- int num2= dis2.readInt();
- int add = num1 + num2;
- DataOutputStream dos =new DataOutputStream (s.getOutputStream());
- dos.writeInt(add);
- s.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output
- 2.TCPAddClient
- import java.io.*;
- import java.net.*;
- classTCPAddClient
- {
- public static void main(String[] a)
- {
- System.out.println ("Addition of two numbers Client") String host = "localhost";
- int port = 4000; try
- {System.out.println("Enter the two numbers");
- DataInputStream in1= new DataInputStream(System.in);
- DataInputStream in2= new DataInputStream(System.in);
- Socket s = new Socket (host , port);
- int num1 =Integer.parseInt(in1.readLine());
- int num2 =Integer.parseInt(in2.readLine());
- DataOutputStream dos1= new DataOutputStream (s.getOutputStream());
- dos1.writeInt (num1);
- DataOutputStream dos2= new DataOutputStream (s.getOutputStream());
- dos2.writeInt (num2);
- DataInputStream dis = new DataInputStream(s.getInputStream());
- int i = dis.readInt();
- System.out.println ("Addition of the two numbers :" +i);
- s.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output
- Practical 2C: A client server based program using UDP to find the square of the given number.
- Code:
- 1.UDPServerSquare.java
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- public class UDPServerSquare
- {
- public static void main(String args[]) throws Exception
- {
- DatagramSocket ds =new DatagramSocket(1111);
- byte[] rec= new byte[1024];
- byte[] send = new byte[1024];
- while (true)
- {
- DatagramPacketrecdp = new DatagramPacket (rec, rec.length);
- ds.receive (recdp);
- String str= new String (recdp.getData());
- intnum = Integer.parseInt(str.trim());
- System.out.println ("From Client :" + num);
- int result = num *num;
- InetAddressip =recdp.getAddress();
- int port = recdp.getPort();
- String data1= String.valueOf(result);
- send = data1.getBytes();
- DatagramPacketsenddp=new DatagramPacket (send,send.length,ip,port);
- ds.send(senddp);
- }
- }
- }
- Output:
- 2.UDPClientSquare Code:
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- public class UDPClientSquare
- {
- public static void main(String args[]) throws Exception
- {
- DatagramSocket ds =new DatagramSocket();
- byte[] rec= new byte[1024];
- byte[] send = new byte[1024];
- System.out.println ("Enter the number to be squared");
- BufferedReaderbr = new BufferedReader (new InputStreamReader (System.in));
- intnum = Integer.parseInt(br.readLine());
- String data = String.valueOf (num);
- send = br.readLine().getBytes();
- InetAddressip = InetAddress.getLocalHost();
- DatagramPacketsenddp = new DatagramPacket (send ,send.length, ip ,1111);
- ds.send (senddp);
- DatagramPacketrecdp = new DatagramPacket (rec, rec.length);
- ds.receive (recdp);
- String str= new String (recdp.getData());
- int result = Integer.parseInt (str.trim());
- System.out.println ("Square of the number is :" + str); ds.close();
- }
- }
- Output:
- Practical 2D: A Client Server based program to convert the entered string to Uppercase UDPServer.java
- Code:
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- public class UDPServerUcase
- {
- public static void main(String args[]) throws Exception {
- DatagramSocket ds =new DatagramSocket(1111); byte[] rec= new byte[1024];
- byte[] send = new byte[1024]; while (true)
- {
- DatagramPacketrecdp = new DatagramPacket (rec, rec.length);
- ds.receive (recdp);
- String str= new String (recdp.getData());
- System.out.println ("From Client :" + str);
- String str1 = (str.toUpperCase().trim());
- InetAddressip =recdp.getAddress();
- int port = recdp.getPort();
- send = str1.getBytes();
- DatagramPacketsenddp=new DatagramPacket (send,send.length,ip,port);
- ds.send(senddp);
- }
- }
- }
- 2. UDPClient.java Code:
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- public class UDPClientUcase
- {
- public static void main(String args[]) throws Exception {
- DatagramSocket ds =new DatagramSocket(); byte[] rec= new byte[1024];
- byte[] send = new byte[1024];
- System.out.println ("Enter the string to be converted");
- BufferedReaderbr = new BufferedReader (new InputStreamReader(System.in));
- send = br.readLine().getBytes();
- InetAddressip = InetAddress.getLocalHost();
- DatagramPacketsenddp = new DatagramPacket (send ,send.length, ip,1111);
- ds.send (senddp);
- DatagramPacketrecdp = new DatagramPacket (rec, rec.length);
- ds.receive (recdp);
- String str= new String (recdp.getData());
- System.out.println ("String in uppercase is :" + str.trim());
- ds.close();
- }
- }
- Output
- Practical 2E:A Multicast Socket Example
- Code:
- 1. BroadcastServer.java
- import java.io.*; import java.net.*; importjava.util.*;
- public class BroadcastServer
- {
- public static final int PORT=1234;
- public static void main(String args[])throws Exception
- {
- MulticastSocket socket; DatagramPacket packet; InetAddressaddr;
- addr=InetAddress.getByName("224.0.0.1"); socket=new MulticastSocket(); socket.joinGroup(addr);
- byte[] data=null;
- for(;;)
- {
- Thread.sleep(1000);
- System.out.println("Sending");
- String str=("This is Sagar Calling");
- data=str.getBytes();
- packet=new DatagramPacket(data,str.length(),addr,PORT);
- socket.send(packet);
- }
- }
- }
- 2. Broadcast Client
- Code:
- import java.io.*; import java.net.*; importjava.util.*;
- public class BroadcastClient
- {
- public static final int PORT=1234;
- public static void main(String args[])throws Exception
- {
- MulticastSocket socket; DatagramPacket packet;
- InetAddressaddr; addr=InetAddress.getByName("224.0.0.1"); socket=new MulticastSocket(PORT); socket.joinGroup(addr);
- byte[] data=new byte[100];
- packet=new DatagramPacket(data,data.length); for(;;)
- {
- }
- }
- socket.receive(packet);
- String str=new String(packet.getData()); System.out.println("Message " + packet.getAddress() + "Messageis:"+str);
- }
- Output
- Practical No.3
- Aim: Write a program to show the object communication using RMI.
- Practical 3A: A RMI based application program to display current date and time.
- Code:Prac2i.java
- importjava.rmi.*;
- public interface prac2i extends Remote
- {
- public String showdate() throws RemoteException;
- public String showtime() throws RemoteException;
- }
- Code:Prac2s.java
- importjava.rmi.*;
- importjava.rmi.server.*;
- importjava.util.*;
- public class prac2s extends UnicastRemoteObject implements prac2i {
- public prac2s() throws RemoteException
- {
- System.out.println ("Sever Created");
- }
- public String showdate() throws RemoteException {
- Date d = new Date(); returnd.toString();
- }
- public String showtime() throws RemoteException
- {
- Date d = new Date();
- String s = d.getHours() +":" + d.getMinutes() + ":" + d.getSeconds(); return s;
- }
- public static void main (String args[])
- {
- try
- {
- prac2sps = new prac2s(); Naming.rebind("xyz", ps);
- }
- catch (Exception e)
- {}
- }
- }
- Prac2c.java
- importjava.rmi.*;
- public class prac2c
- {
- public static void main(String args[])
- {
- try
- {
- prac2i p1=(prac2i) Naming.lookup("xyz");
- System.out.println (p1.showdate());
- System.out.println(p1.showtime());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- Output:
- Practical 3B: A RMI based application program that illustrates calculator
- Code: cali.java
- import java.rmi.*;
- public interface cali extends Remote
- {
- publicint sum (int a, int b) throws RemoteException;
- publicint sub (int a , int b ) throws RemoteException;
- publicintmul (int a , int b) throws RemoteException;
- }
- cals.java
- import java.rmi.*;
- import java.rmi.server.*;
- public class cals extends UnicastRemoteObject implements cali
- {
- public cals() throws RemoteException
- {
- System.out.println ("Server is Initiated");
- }
- public int sum (int first , int second) throws RemoteException
- {
- return first + second ;
- }
- public int sub (int first , int second) throws RemoteException
- {
- return first - second ;
- }
- public int mul (int first , int second) throws RemoteException
- {
- return first * second ;
- }
- public static void main( String args[])
- {
- try
- {
- cals cs = new cals(); Naming.rebind ("abc", cs);
- }
- catch (Exception e)
- {
- System.out.println("Exception occured :" + e.getMessage());
- }
- }
- }
- calc.java
- importjava.rmi.*;
- import java.io.*;
- public class calc
- {
- public static void main(String args[])
- {
- try
- {
- cali c = (cali) Naming.lookup("abc"); BufferedReaderbr = new BufferedReader(new
- InputStreamReader(System.in));
- System.out.println(" Enter the first number");
- String str1=br.readLine();
- System.out.println(" Enter the second number");
- String str2=br.readLine();
- System.out.println ("Sum of two numbers is : " +
- c.sum(Integer.parseInt(str1) , Integer.parseInt(str2)));
- System.out.println ("Difference of two numbers is : " +
- c.sub(Integer.parseInt(str1) ,Integer.parseInt(str2)));
- System.out.println ("Multiplication of two numbers is : " + c.mul(Integer.parseInt(str1) , Integer.parseInt(str2)));
- }
- catch (Exception e)
- {
- System.out.println("Exception occured : " + e.getMessage());
- }
- }
- }
- Output:
- Practical No.4
- Aim: Show the implementation of Remote Procedure Call.
- Practical 4A: A program to implement simple calculator operations like addition, subtraction, multiplication and division.
- Code:
- 1.RPCServer.java
- importjava.util.*;
- import java.net.*;
- import java.io.*;
- classRPCServer
- {
- DatagramSocket ds;
- DatagramPacketdp;
- String str, methodname , result; int val1 , val2;
- RPCServer()
- {
- try
- {
- ds= new DatagramSocket(1200);
- byte b[]= new byte[1024];
- while (true)
- {
- dp = new DatagramPacket (b , b.length);
- ds.receive (dp);
- str = new String (dp.getData(),0,dp.getLength());
- if (str.equalsIgnoreCase("q"))
- {
- System.exit (1);
- }
- else
- {
- StringTokenizerst = new StringTokenizer(str," ");
- int i =0;
- while (st.hasMoreTokens())
- {
- String token = st.nextToken();
- methodname =token;
- val1 = Integer.parseInt (st.nextToken());
- val2 = Integer.parseInt (st.nextToken());
- }//while token
- } //else System.out.println(str);
- InetAddressia = InetAddress.getLocalHost();
- if (methodname.equalsIgnoreCase("add"))
- {
- result = "" + add(val1,val2);
- }
- else if (methodname.equalsIgnoreCase("sub"))
- {
- result = "" + sub(val1,val2);
- }
- else if (methodname.equalsIgnoreCase("mul"))
- {
- result = "" + mul(val1,val2);
- }
- else if (methodname.equalsIgnoreCase("div"))
- {
- result = "" + div(val1,val2);
- }
- byte b1[]=result.getBytes();
- DatagramSocket ds1= new DatagramSocket();
- DatagramPacket dp1 = new DatagramPacket (b1,b1.length,InetAddress.getLocalHost(),1300);
- System.out.println("result: "+ result +"\n"); ds1.send (dp1);
- } //while
- } //try
- catch (Exception e)
- {
- e.printStackTrace();
- }
- } //constructor
- publicint add (int val1 , int val2)
- {
- return val1+val2;
- }
- publicint sub(int val1 ,int val2)
- {
- return val1-val2;
- }
- publicintmul (int val1 ,int val2)
- {
- return val1*val2;
- }
- publicint div (int val1 ,int val2)
- {
- return val1/val2;
- }
- public static void main (String[] args)
- {
- newRPCServer();
- }
- } //class
- 2. RPCClient.java
- import java.io.*; import java.net.*;
- classRPCClient
- {
- RPCClient()
- {
- try
- {
- InetAddressia=InetAddress.getLocalHost();
- DatagramSocket ds= new DatagramSocket();
- DatagramSocket ds1=new DatagramSocket(1300);
- System.out.println("\n RPC Client \n");
- System.out.println ("Enter method name and parameters ");
- while (true)
- {
- BufferedReaderbr = new BufferedReader(new InputStreamReader(System.in));
- String str=br.readLine();
- byte b[]= str.getBytes();
- DatagramPacketdp = new DatagramPacket (b ,b.length , ia, 1200);
- ds.send(dp);
- dp= new DatagramPacket (b, b.length);
- ds1.receive(dp);
- String s = new String (dp.getData(),0,dp.getLength());
- System.out.println("\n Result = " + s + "\n");
- } //while
- }//try
- catch (Exception e)
- {
- e.printStackTrace();
- } //catch
- }//constructor
- public static void main( String args[])
- {
- newRPCClient();
- }
- }
- Output:
- Practical No.5
- Aim: Write a program to execute any one mutual exclusion algorithm.
- Code:
- EchoClientOne.java
- import java.io.*;
- import java.net.*;
- public class EchoClientOne
- {
- public static void main(String ards[]) throws IOException
- {
- Socket s = new Socket("localhost",7000);
- PrintStream out = new PrintStream (s.getOutputStream());
- ServerSocketss = new ServerSocket(7001); Socket s1 = ss.accept();
- BufferedReader in1= new BufferedReader(new InputStreamReader(s1.getInputStream()));
- PrintStream out1 = new PrintStream (s1.getOutputStream());
- BufferedReaderbr = new BufferedReader (new InputStreamReader(System.in));
- String str = "Token";
- while (true)
- {
- if (str.equalsIgnoreCase("Token"))
- {
- System.out.println("Do you want to send some data");
- System.out.println("Enter yes or no");
- str = br.readLine();
- if (str.equalsIgnoreCase("Yes"))
- {
- System.out.println("Enter the data");
- str = br.readLine();
- out.println(str);
- }
- out1.println ("Token");
- }
- System.out.println("Waiting for token");
- str = in1.readLine();
- }
- }
- }
- EchoClientTwo.java
- import java.io.*;
- import java.net.*;
- public class EchoClientTwo
- {
- public static void main(String ards[]) throws IOException
- {
- Socket s = new Socket("localhost",7000);
- PrintStream out = new PrintStream (s.getOutputStream());
- Socket s2 = new Socket("localhost",7001);
- BufferedReader in2= new BufferedReader(new InputStreamReader(s2.getInputStream()));
- PrintStream out2= new PrintStream (s2.getOutputStream());
- BufferedReaderbr = new BufferedReader (new InputStreamReader(System.in));
- String str="Token";
- while (true)
- {
- System.out.println("Waiting for token");
- }
- str = in2.readLine();
- if (str.equalsIgnoreCase("Token"))
- {
- System.out.println("Do you want to send some data");
- System.out.println("Enter yes or no");
- str = br.readLine();
- if (str.equalsIgnoreCase("Yes"))
- {
- System.out.println("Enter the data"); str = br.readLine();
- out.println(str);
- }
- out2.println ("Token");
- }
- }
- }
- }
- EchoServer.java
- import java.io.*;
- import java.net.*;
- public class EchoServer implements Runnable
- {
- Socket socket = null;
- staticServerSocketss;
- EchoServer( SocketnewSocket)
- {
- this.socket = newSocket;
- }
- public static void main (String args[]) throws IOException
- {
- ss = new ServerSocket(7000);
- System.out.println ("Server Started");
- while (true)
- {
- Socket s=ss.accept();
- EchoServeres = new EchoServer(s);
- Thread t = new Thread(es);
- t.start();
- }
- }
- public void run()
- {
- try
- {
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- while(true)
- {
- System.out.println (in.readLine());
- }
- }
- catch (Exception e)
- {}
- }
- }
- Output:
- Practical No.6
- Aim: Show the implementation of any one clock synchronization algorithm.
- Code:
- 1. SCServer.java
- import java.io.*;
- import java.net.*;
- importjava.sql.*;
- public class SCServer
- {
- public static void main(String args[])throws Exception
- {
- InetAddresslclhost;
- loclhost=InetAddress.getLocalHost();
- longmaxtime,skewtime,datatime;
- String maxtimestr,skewtimestr;
- BufferedReaderbr;
- ClntServerser=new ClntServer(lclhost);
- System.out.println("Enter the maximum time");
- br = new BufferedReader(new
- InputStreamReader(System.in));
- maxtimestr=br.readLine();
- System.out.println("Enter the maximum skew time");
- br = new BufferedReader(new InputStreamReader(System.in));
- skewtimestr=br.readLine();
- maxtime=Long.parseLong(maxtimestr); s
- kewtime=Long.parseLong(skewtimestr);
- while(true)
- {
- datatime =System.currentTimeMillis();
- long G = datatime-maxtime-skewtime;
- System.out.println("G ="+G);
- ser.setTimeStamp(new Timestamp(G));
- ser.recPort(8001);
- ser.recData();
- }
- }
- }
- classClntServer
- {
- InetAddresslclhost;
- intrecport;
- Timestamp obtmp;
- ClntServer(InetAddresslclhost)
- {
- this.lclhost = lclhost;
- }
- voidrecPort(intrecport)
- {
- this.recport = recport;
- }
- voidsetTimeStamp(Timestamp obtmp)
- {
- this.obtmp = obtmp;
- }
- voidrecData()throws Exception
- {
- String msgstr="";
- DatagramSocket ds;
- DatagramPacketdp;
- BufferedReaderbr;
- bytebuf[] = new byte[256];
- ds = new DatagramSocket(recport);
- dp = new DatagramPacket(buf,buf.length);
- ds.receive(dp);
- ds.close();
- msgstr = new String(dp.getData(),0,dp.getLength());
- System.out.println(msgstr);
- Timestamp obtmp = new Timestamp(Long.parseLong(msgstr));
- if(this.obtmp.before(obtmp) == true)
- {
- System.out.println("The Message is accepted");
- }
- else
- {
- System.out.println("The Message is rejected");
- }
- }
- }
- 3. SCClient.java
- import java.io.*;
- import java.net.*;
- public class SCClient
- {
- public static void main(String args[]) throws Exception
- {
- InetAddresslclhost;
- loclhost = InetAddress.getLocalHost();
- while (true)
- {
- Client cntl = new Client(lclhost);
- cntl.sendPort(9001);
- cntl.sendData();
- }
- }
- }
- class Client
- {
- InetAddresslclhost; intsenport;
- Client (InetAddresslclhost)
- {
- this.lclhost = loclhost;
- }
- voidsendPort (intsenport)
- {
- this.senport = senport;
- }
- voidsendData() throws Exception
- {
- DatagramPacketdp;
- DatagramSocket ds;
- BufferedReaderbr;
- br = new BufferedReader (new InputStreamReader(System.in));
- System.out.println ("Enter The Data");
- String str = br.readLine();
- ds = new DatagramSocket (senport);
- dp = new DatagramPacket(str.getBytes(),str.length(),lclhost,senport-1000);
- ds.send(dp);
- ds.close();
- }
- }
- Output:
- Practical No.7
- Aim: Write a program to implement two phase commit protocol.
- Code:
- 1. Server.java
- import java.io.*;
- import java.net.*;
- importjava.util.*;
- public class Server
- {
- boolean closed=false,inputFromAll=false;
- List<clientThread> t;
- List<String> data;
- Server()
- {
- t= new ArrayList<clientThread>();
- data= new ArrayList<String>();
- }
- public static void main(String args[])
- {
- Socket clientSocket = null;
- ServerSocketserverSocket = null;
- intport_number=1111;
- Server ser=new Server();
- try
- {
- serverSocket = new ServerSocket(port_number);
- }
- catch (IOException e)
- {
- System.out.println(e);
- }
- while(!ser.closed)
- {
- try
- {
- clientSocket = serverSocket.accept();
- clientThreadth=new clientThread(ser,clientSocket);
- (ser.t).add(th);
- System.out.println("\nNow Total clients are : "+(ser.t).size());
- (ser.data).add("NOT_SENT");
- th.start();
- }
- catch (IOException e) {}
- }
- try
- {
- serverSocket.close();
- }
- catch(Exception e1){}
- }
- }
- classclientThread extends Thread
- {
- DataInputStream is = null;
- String line;
- String destClient="";
- String name;
- PrintStreamos = null;
- Socket clientSocket = null;
- String clientIdentity;
- Server ser;
- publicclientThread(Server ser,SocketclientSocket)
- {
- this.clientSocket=clientSocket;
- this.ser=ser;
- }
- public void run()
- {
- try
- {
- is = new DataInputStream(clientSocket.getInputStream());
- os = new PrintStream(clientSocket.getOutputStream());
- os.println("Enter your name.");
- name = is.readLine();
- clientIdentity=name;
- os.println("Welcome "+name+" to this 2 Phase Application.\nYou will receive a vote Request now...");
- os.println("VOTE_REQUEST\nPlease enter COMMIT or ABORT to proceed : ");
- for(int i=0; i<(ser.t).size(); i++)
- {
- if((ser.t).get(i)!=this)
- {
- ((ser.t).get(i)).os.println("---A new user "+name+" entered the Appilcation---");
- }
- }
- while (true)
- {
- line = is.readLine();
- if(line.equalsIgnoreCase("ABORT"))
- {
- System.out.println("\nFrom '"+clientIdentity+"' : ABORT\n\nSince aborted we will not wait for inputs from other clients.");
- System.out.println("\nAborted....");
- for(int i=0; i<(ser.t).size(); i++)
- {
- ((ser.t).get(i)).os.println("GLOBAL_ABORT");
- ((ser.t).get(i)).os.close();
- ((ser.t).get(i)).is.close();
- }
- break;
- }
- if(line.equalsIgnoreCase("COMMIT"))
- {
- System.out.println("\nFrom '"+clientIdentity+"' : COMMIT");
- if((ser.t).contains(this))
- {
- (ser.data).set((ser.t).indexOf(this), "COMMIT"); for(int j=0;j<(ser.data).size();j++)
- {
- if(!(((ser.data).get(j)).equalsIgnoreCase("NOT_SENT")))
- {
- ser.inputFromAll=true;
- continue;
- }
- else
- {
- ser.inputFromAll=false;
- System.out.println("\nWaiting for inputs from other clients."); break;
- }
- }
- if(ser.inputFromAll)
- {
- System.out.println("\n\nCommited....");
- for(int i=0; i<(ser.t).size(); i++)
- {
- ((ser.t).get(i)).os.println("GLOBAL_COMMIT");
- ((ser.t).get(i)).os.close();
- ((ser.t).get(i)).is.close();
- }
- break;
- }
- }//if t.contains
- }//commit
- }//while
- ser.closed=true;
- clientSocket.close();
- }
- catch(IOException e){};
- }
- }
- 2. Client.java
- import java.io.*;
- import java.net.*;
- public class Client implements Runnable
- {
- static Socket clientSocket = null;
- staticPrintStreamos = null;
- staticDataInputStream is = null;
- staticBufferedReaderinputLine = null;
- staticboolean closed = false;
- public static void main(String[] args)
- {
- intport_number=1111;
- String host="localhost";
- try
- {
- clientSocket = new Socket(host, port_number);
- inputLine = new BufferedReader(new InputStreamReader(System.in));
- os= new PrintStream(clientSocket.getOutputStream());
- is = new DataInputStream(clientSocket.getInputStream());
- }
- catch (Exception e)
- {
- System.out.println("Exception occurred : "+e.getMessage());
- }
- if (clientSocket != null &&os != null && is != null)
- {
- try
- {
- new Thread(new Client()).start();
- while (!closed)
- {
- os.println(inputLine.readLine());
- }
- os.close();
- is.close();
- clientSocket.close();
- }
- catch (IOException e)
- {
- System.err.println("IOException: " + e);
- }
- }
- }
- public void run()
- {
- String responseLine;
- try
- {
- while ((responseLine = is.readLine()) != null)
- {
- System.out.println("\n"+responseLine);
- if (responseLine.equalsIgnoreCase("GLOBAL_COMMIT")==true
- || responseLine.equalsIgnoreCase("GLOBAL_ABORT")==true )
- {
- break;
- }
- }
- closed=true;
- }
- catch (IOException e)
- {
- System.err.println("IOException: " + e);
- }
- }
- }
- OUTPUT:
- Practical No.8
- Aim: Implement the concept of distributed file system architecture.
- Network File System: Server Side Configuration
- Set ip address of server 192.159.1.27
- Check if nfs is installed on your machine.
- rpm –qa | grep nfs
- #set iptables off
- #set firewall off
- #set vsftpd off
- #set imapd off
- #service nfs start
- #pwd
- /root
- #mkdir mscitp1PPb
- #cd mscitp1PPb #pwd
- /root/mscitp1ppb #vi ved
- Type something and save
- #vi monu
- Type something and save
- #vi lochu
- Type something and save
- #ls
- ved monu lochu
- #vi /etc/exports
- Add the following
- /root/mscitp1ppb(press atab key) 192.159.1.28(rw,sync)
- Save and exit
- #showmount -e
- #service nfs restart
- Client Side Configuration:
- Set ip address of server 192.159.1.28
- #service iptables stop
- #service ftpd stop #pwd
- /root
- #mkdir ppbstuff
- #mount –t nfs 192.159.1.27:/root/mscitp1ppb /root/ppbstuff
- #cd ppbstuff
- #cat ved
- #cat monu
- #cat lochu
- Conclusion:
- Distributed file system is implemented.
Add Comment
Please, Sign In to add comment