AjuuKaru

DSprac3

Jan 28th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.11 KB | None | 0 0
  1. RMI EXECUTION(3 TERMINAL OPEN)
  2.  
  3. notepad type inside folder create
  4.  
  5. path="c-pf-java-jdk-bin vala path copy "
  6. 1) i)>javac *.java
  7. iii)>rmic implfile
  8. iv)>java serverfile
  9. 2)ii)>start rmiregistry
  10.  
  11. 3)v)>java clientfile
  12.  
  13.  
  14. TCP
  15. 1. tcpServerPrime.java
  16. import java.net.*; import java.io.*;
  17. class tcpServerPrime
  18. {
  19. public static void main(String args[])
  20. {
  21. try
  22. {
  23. ServerSocket ss = new ServerSocket(8001); System.out.println("Server Started..............."); Socket s = ss.accept();
  24. DataInputStream in = new DataInputStream(s.getInputStream()); int x= in.readInt(); DataOutputStream otc = new DataOutputStream(s.getOutputStream()); int y = x/2; if(x ==1 || x ==2 || x ==3)
  25. {
  26. otc.writeUTF(x + "is Prime"); System.exit(0);
  27. }
  28. for(int i=2; i<=y; i++)
  29. {
  30. if(x%i != 0)
  31. {
  32. }
  33. else
  34. {
  35. }
  36. }
  37. }
  38. otc.writeUTF(x + " is Prime");
  39. otc.writeUTF(x + " is not Prime");
  40. catch(Exception e)
  41. {
  42. System.out.println(e.toString());
  43. }
  44. }
  45. }
  46.  
  47. 2. tcpClientPrime.java
  48. import java.net.*; import java.io.*;
  49. class tcpClientPrime
  50. {
  51. public static void main(String args[])
  52. {
  53. try
  54. {
  55. Socket cs = new Socket("LocalHost",8001); BufferedReader infu = new BufferedReader(new
  56. InputStreamReader(System.in));
  57. System.out.println("Enter a number : "); int a = Integer.parseInt(infu.readLine()); DataOutputStream out = new
  58. DataOutputStream(cs.getOutputStream());
  59. out.writeInt(a); DataInputStream in = new
  60. DataInputStream(cs.getInputStream()); System.out.println(in.readUTF()); cs.close();
  61. }
  62. catch(Exception e)
  63. {
  64. System.out.println(e.toString());
  65. }
  66. }
  67. }
  68.  
  69. CHAT
  70. 1. ChatServer.java
  71. import java.net.*; import java.io.*;
  72. class ChatServer
  73. {
  74. public static void main(String args[])
  75. {
  76. try
  77. {
  78. ServerSocket ss = new ServerSocket(8000); System.out.println("Waiting for client to connect.."); Socket s = ss.accept();
  79. BufferedReader br = new BufferedReader(new
  80. InputStreamReader(System.in));
  81. DataOutputStream out = new DataOutputStream(s.getOutputStream()); DataInputStream in = new DataInputStream(s.getInputStream()); String receive, send; while((receive = in.readLine()) != null)
  82. {
  83. if(receive.equals("STOP")) break;
  84. System.out.println("Client Says : "+receive); System.out.print("Server Says : ");
  85. send = br.readLine(); out.writeBytes(send+"\n");
  86. }
  87. br.close();
  88. in.close();
  89. out.close();
  90.  
  91. s.close();
  92. }
  93. catch(Exception e)
  94. {
  95. e.printStackTrace();
  96. }
  97. }
  98. }
  99. 2. ChatClient.java
  100. import java.net.*; import java.io.*;
  101. class ChatClient
  102. {
  103. public static void main(String args[])
  104. {
  105. try
  106. {
  107. Socket s = new Socket("Localhost",8000); BufferedReader br = new BufferedReader(new
  108. InputStreamReader(System.in));
  109. DataOutputStream out = new DataOutputStream(s.getOutputStream()); DataInputStream in = new DataInputStream(s.getInputStream()); String msg; System.out.println("To stop chatting with server type
  110. STOP"); System.out.print("Client Says: "); while((msg = br.readLine()) != null)
  111. {
  112. out.writeBytes(msg+"\n"); if(msg.equals("STOP"))
  113. break;
  114. System.out.println("Server Says : "+in.readLine()); System.out.print("Client Says : ");
  115. }
  116. br.close();
  117. in.close();
  118. out.close();
  119. s.close();
  120. }
  121. catch(Exception e)
  122. {
  123. e.printStackTrace();
  124. }
  125. }
  126. }
  127. UDP
  128. 1. udpServerEO.java
  129. /*Program which finds entered number is even or odd */ import java.io.*;
  130. import java.net.*;
  131. public class udpServerEO
  132. {
  133. public static void main(String args[])
  134. {
  135. try
  136. {
  137. DatagramSocket ds = new DatagramSocket(2000); byte b[] = new byte[1024];
  138. DatagramPacket dp = new DatagramPacket(b,b.length); ds.receive(dp);
  139. String str = new String(dp.getData(),0,dp.getLength()); System.out.println(str);
  140. int a= Integer.parseInt(str); String s= new String();
  141. if (a%2 == 0)
  142. s = "Number is even";
  143. else
  144. s = "Number is odd";
  145. byte b1[] = new byte[1024]; b1 = s.getBytes(); DatagramPacket dp1 = new
  146. DatagramPacket(b1,b1.length,InetAddress.getLocalHost(),1000);
  147. ds.send(dp1);
  148. }
  149. catch(Exception e)
  150. {
  151. e.printStackTrace();
  152. }
  153. }
  154. }
  155. 2. udpClientEO.java
  156. /*Program which finds entered number is even or odd*/
  157. import java.io.*; import java.net.*;
  158. public class udpClientEO
  159. {
  160. public static void main(String args[])
  161. {
  162. try
  163.  
  164. {
  165. DatagramSocket ds = new DatagramSocket(1000); BufferedReader br = new BufferedReader(new
  166. InputStreamReader(System.in));
  167. System.out.println("Enter a number : "); String num = br.readLine();
  168. byte b[] = new byte[1024]; b=num.getBytes(); DatagramPacket dp = new
  169. DatagramPacket(b,b.length,InetAddress.getLocalHost(),2000);
  170. ds.send(dp);
  171. byte b1[] = new byte[1024]; DatagramPacket dp1 = new
  172. DatagramPacket(b1,b1.length); ds.receive(dp1);
  173. String str = new String(dp1.getData(),0,dp1.getLength()); System.out.println(str);
  174. }
  175. catch(Exception e)
  176. {
  177. e.printStackTrace();
  178. }
  179. }
  180. }
  181.  
  182. 1. udpServerFact.java
  183. /*Program which calculate factorial of a number*/ import java.io.*;
  184. import java.net.*;
  185. public class udpServerFact
  186. {
  187. public static void main(String args[])
  188. {
  189. try
  190. {
  191. DatagramSocket ds = new DatagramSocket(2000); byte b[] = new byte[1024];
  192. DatagramPacket dp = new DatagramPacket(b,b.length); ds.receive(dp);
  193. String str = new String(dp.getData(),0,dp.getLength()); System.out.println(str);
  194. int a= Integer.parseInt(str); int f = 1, i;
  195. String s= new String(); for(i=1;i<=a;i++)
  196. {
  197. f=f*i;
  198. }
  199. s=Integer.toString(f);
  200. String str1 = "The Factorial of " + str + " is : " + f; byte b1[] = new byte[1024]; b1 = str1.getBytes(); DatagramPacket dp1 = new
  201. DatagramPacket(b1,b1.length,InetAddress.getLocalHost(),1000);
  202. ds.send(dp1);
  203. }
  204. catch(Exception e)
  205. {
  206. e.printStackTrace();
  207. }
  208. }
  209. }
  210. 2. udpClientFact.java
  211. /*Program which calculate factorial of a number*/ import java.io.*;
  212.  
  213. import java.net.*;
  214. public class udpClientFact
  215. {
  216. public static void main(String args[])
  217. {
  218. try
  219. {
  220. DatagramSocket ds = new DatagramSocket(1000); BufferedReader br = new BufferedReader(new
  221. InputStreamReader(System.in));
  222. System.out.println("Enter a number : "); String num = br.readLine();
  223. byte b[] = new byte[1024]; b=num.getBytes(); DatagramPacket dp = new
  224. DatagramPacket(b,b.length,InetAddress.getLocalHost(),2000);
  225. ds.send(dp);
  226. byte b1[] = new byte[1024];
  227. DatagramPacket dp1 = new DatagramPacket(b1,b1.length); ds.receive(dp1);
  228. String str = new String(dp1.getData(),0,dp1.getLength()); System.out.println(str);
  229. }
  230. catch(Exception e)
  231. {
  232. e.printStackTrace();
  233. }
  234. }
  235. }
  236.  
  237. RMI
  238. 1
  239. 1. InterDate.java
  240. import java.rmi.*;
  241. public interface InterDate extends Remote
  242. {
  243. public String display() throws Exception;
  244. }
  245. 2. ServerDate.java
  246. import java.rmi.*; import java.rmi.server.*; import java.util.*;
  247. public class ServerDate extends UnicastRemoteObject implements InterDate {
  248. public ServerDate() throws Exception
  249. {
  250. }
  251. public String display() throws Exception
  252. {
  253. String str = "";
  254. Date d = new Date(); str = d.toString(); return str;
  255. }
  256. public static void main(String args[]) throws Exception {
  257. ServerDate s1 = new ServerDate(); Naming.bind("DS",s1); System.out.println("Object registered.....");
  258. }
  259. }
  260. 3. ClientDate.java
  261. import java.rmi.*; import java.io.*;
  262.  
  263. public class ClientDate
  264. {
  265. public static void main(String args[]) throws Exception {
  266. String s1;
  267. InterDate h1 = (InterDate)Naming.lookup("DS"); s1 = h1.display();
  268. System.out.println(s1);
  269. }
  270. }
  271.  
  272. 1STEP= javac file name.java(3file)
  273. 2step= rmic server
  274. 3step= rmiregistry
  275.  
  276. java server
  277.  
  278. java client
  279. 2)
  280. 1. InterConvert.java
  281. import java.rmi.*;
  282. public interface InterConvert extends Remote
  283. {
  284. public String convertDigit(String no) throws Exception;
  285. }
  286. 2. ServerConvert.java
  287. import java.rmi.*; import java.rmi.server.*;
  288. public class ServerConvert extends UnicastRemoteObject implements InterConvert {
  289. public ServerConvert() throws Exception
  290. {
  291. }
  292. public String convertDigit(String no) throws Exception
  293. {
  294. String str = "";
  295. for(int i = 0; i < no.length(); i++)
  296. {
  297. int p = no.charAt(i); if( p == 48)
  298. {
  299. str += "zero ";
  300. }
  301. if( p == 49)
  302. {
  303. str += "one ";
  304. }
  305. if( p == 50)
  306. {
  307. str += "two ";
  308. }
  309. if( p == 51)
  310. {
  311. str += "three ";
  312. }
  313. if( p == 52)
  314. {
  315. str += "four ";
  316.  
  317. }
  318. if( p == 53)
  319. {
  320. str += "five ";
  321. }
  322. if( p == 54)
  323. {
  324. str += "six ";
  325. }
  326. if( p == 55)
  327. {
  328. str += "seven ";
  329. }
  330. if( p == 56)
  331. {
  332. str += "eight ";
  333. }
  334. if( p == 57)
  335. {
  336. str += "nine ";
  337. }
  338. }
  339. return str;
  340. }
  341. public static void main(String args[]) throws Exception {
  342. ServerConvert s1 = new ServerConvert(); Naming.bind("Wrd",s1); System.out.println("Object registered....");
  343. }
  344. }
  345. 3. ClientConvert.java
  346. import java.rmi.*; import java.io.*;
  347. public class ClientConvert
  348. {
  349. public static void main(String args[]) throws Exception {
  350. InterConvert h1 = (InterConvert)Naming.lookup("Wrd"); BufferedReader br = new BufferedReader(new
  351. InputStreamReader(System.in));
  352. System.out.println("Enter a number : \t"); String no = br.readLine();
  353. String ans = h1.convertDigit(no);
  354. System.out.println("The word representation of the entered digit is : " +ans);
  355. }
  356. }
  357.  
  358. RPC
  359. 1. RPCServer.java
  360. import java.util.*; import java.net.*;
  361. class RPCServer
  362. {
  363. DatagramSocket ds;
  364. DatagramPacket dp;
  365. String str,methodName,result; int val1,val2;
  366. RPCServer()
  367. {
  368. try
  369. {
  370. ds=new DatagramSocket(1200); byte b[]=new byte[4096];
  371. while(true)
  372. {
  373. dp=new DatagramPacket(b,b.length); ds.receive(dp);
  374. str=new String(dp.getData(),0,dp.getLength());
  375. if(str.equalsIgnoreCase("q"))
  376. {
  377. }
  378. else
  379. {
  380. System.exit(1);
  381. StringTokenizer st = new StringTokenizer(str," "); int i=0;
  382. while(st.hasMoreTokens())
  383. {
  384. String token=st.nextToken(); methodName=token;
  385. val1 = Integer.parseInt(st.nextToken()); val2 = Integer.parseInt(st.nextToken());
  386. }
  387.  
  388. }
  389. System.out.println(str);
  390. InetAddress ia = InetAddress.getLocalHost();
  391. if(methodName.equalsIgnoreCase("add"))
  392. {
  393. result= "" + add(val1,val2);
  394. }
  395. else if(methodName.equalsIgnoreCase("sub"))
  396. {
  397. result= "" + sub(val1,val2);
  398. }
  399. else if(methodName.equalsIgnoreCase("mul"))
  400. {
  401. result= "" + mul(val1,val2);
  402. }
  403. else if(methodName.equalsIgnoreCase("div"))
  404. {
  405. result= "" + div(val1,val2);
  406. }
  407. byte b1[]=result.getBytes();
  408. DatagramSocket ds1 = new DatagramSocket(); DatagramPacket dp1 = new
  409. DatagramPacket(b1,b1.length,InetAddress.getLocalHost(), 1300);
  410. System.out.println("result : "+result+"\n"); ds1.send(dp1);
  411. }
  412. }
  413. catch (Exception e)
  414. {
  415. e.printStackTrace();
  416. }
  417. }
  418. public int add(int val1, int val2)
  419. {
  420. return val1+val2;
  421. }
  422. public int sub(int val3, int val4)
  423. {
  424. return val3-val4;
  425. }
  426. public int mul(int val3, int val4)
  427. {
  428. return val3*val4;
  429. }
  430. public int div(int val3, int val4)
  431. {
  432. return val3/val4;
  433. }
  434.  
  435. public static void main(String[] args)
  436. {
  437. new RPCServer();
  438. }
  439. }
  440. 2. RPCClient.java
  441. import java.io.*; import java.net.*;
  442. class RPCClient
  443. {
  444. RPCClient()
  445. {
  446. 4\n");
  447. try
  448. {
  449. InetAddress ia = InetAddress.getLocalHost(); DatagramSocket ds = new DatagramSocket(); DatagramSocket ds1 = new DatagramSocket(1300); System.out.println("\nRPC Client\n");
  450. System.out.println("Enter method name and parameter like add 3
  451. while (true)
  452. {
  453. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  454. String str = br.readLine(); byte b[] = str.getBytes(); DatagramPacket dp = new
  455. DatagramPacket(b,b.length,ia,1200);
  456. ds.send(dp);
  457. dp = new DatagramPacket(b,b.length); ds1.receive(dp);
  458. String s = new String(dp.getData(),0,dp.getLength()); System.out.println("\nResult = " + s + "\n");
  459. }
  460. }
  461. catch (Exception e)
  462. {
  463. e.printStackTrace();
  464. }
  465. }
  466. public static void main(String[] args)
  467. {
  468. new RPCClient();
  469. }
  470. }
  471.  
  472. 1. RPCNumServer.java
  473. import java.util.*; import java.net.*; import java.io.*; class RPCNumServer
  474. {
  475. DatagramSocket ds;
  476.  
  477. DatagramPacket dp;
  478. String str,methodName,result; int val;
  479. RPCNumServer()
  480. {
  481. try
  482. {
  483. ds=new DatagramSocket(1200); byte b[]=new byte[4096]; while(true)
  484. {
  485. dp=new DatagramPacket(b,b.length); ds.receive(dp);
  486. str=new String(dp.getData(),0,dp.getLength()); if(str.equalsIgnoreCase("q")) {
  487. System.exit(1);
  488. }
  489. else
  490. {
  491. StringTokenizer st = new StringTokenizer(str," "); int i=0;
  492. while(st.hasMoreTokens())
  493. {
  494. String token=st.nextToken(); methodName=token;
  495. val = Integer.parseInt(st.nextToken());
  496. }
  497. }
  498. System.out.println(str);
  499. InetAddress ia = InetAddress.getLocalHost(); if(methodName.equalsIgnoreCase("square"))
  500. {
  501. result= "" + square(val);
  502. }
  503. else if(methodName.equalsIgnoreCase("squareroot"))
  504. {
  505. result= "" + squareroot(val);
  506. }
  507. else if(methodName.equalsIgnoreCase("cube"))
  508. {
  509. result= "" + cube(val);
  510. }
  511. else if(methodName.equalsIgnoreCase("cuberoot"))
  512. {
  513. result= "" + cuberoot(val);
  514. }
  515. byte b1[]=result.getBytes();
  516. DatagramSocket ds1 = new DatagramSocket();
  517.  
  518. DatagramPacket dp1 = new DatagramPacket(b1,b1.length,InetAddress.getLocalHost(), 1300);
  519. System.out.println("result : "+result+"\n"); ds1.send(dp1);
  520. }
  521. }
  522. catch (Exception e)
  523. {
  524. e.printStackTrace();
  525. }
  526. }
  527. public double square(int a) throws Exception
  528. {
  529. double ans; ans = a*a; return ans;
  530. }
  531. public double squareroot(int a) throws Exception
  532. {
  533. double ans;
  534. ans = Math.sqrt(a); return ans;
  535. }
  536. public double cube(int a) throws Exception
  537. {
  538. double ans; ans = a*a*a; return ans;
  539. }
  540. public double cuberoot(int a) throws Exception
  541. {
  542. double ans;
  543. ans = Math.cbrt(a); return ans;
  544. }
  545. public static void main(String[] args)
  546. {
  547. new RPCNumServer();
  548. }
  549. }
  550. 2. RPCNumClient.java
  551. import java.io.*; import java.net.*; class RPCNumClient
  552. {
  553. RPCNumClient()
  554. {
  555. try
  556. {
  557.  
  558. InetAddress ia = InetAddress.getLocalHost(); DatagramSocket ds = new DatagramSocket(); DatagramSocket ds1 = new DatagramSocket(1300); System.out.println("\nRPC Client\n");
  559. System.out.println("1. Square of the number - square\n2. Square root of the number - squareroot\n3. Cube of the number - cube\n4. Cube root of the number - cuberoot");
  560. System.out.println("Enter method name and the number\n"); while (true)
  561. {
  562. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  563. String str = br.readLine(); byte b[] = str.getBytes(); DatagramPacket dp = new
  564. DatagramPacket(b,b.length,ia,1200);
  565. ds.send(dp);
  566. dp = new DatagramPacket(b,b.length); ds1.receive(dp);
  567. String s = new String(dp.getData(),0,dp.getLength()); System.out.println("\nResult = " + s + "\n");
  568. }
  569. }
  570. catch (Exception e)
  571. {
  572. e.printStackTrace();
  573. }
  574. }
  575. public static void main(String[] args)
  576. {
  577. new RPCNumClient();
  578. }
  579. }
  580.  
  581. SQL WEBSERVICES
  582. Code Spec
  583. package webservice;
  584. import java.sql.*;
  585. import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.ejb.Stateless;
  586. @WebService() @Stateless()
  587. public class BookWS {
  588. /**
  589. * Web service operation
  590. */
  591. @WebMethod(operationName = "getBookDetails") public String getBookDetails(@WebParam(name = "isbn") String isbn) {
  592. //TODO write your implementation code here: Connection dbcon = null;
  593. Statement stmt = null; ResultSet rs = null; String query = null; try
  594. {
  595. Class.forName("com.mysql.jdbc.Driver").newInstance();
  596. 40
  597. Distributed Systems – Practical Manual – 2018-2019
  598. dbcon =
  599. DriverManager.getConnection("jdbc:mysql://localhost/bookshop","root","123"); stmt = dbcon.createStatement();
  600. query = "select * from books where isbn = '" +isbn+ "'"; rs = stmt.executeQuery(query); rs.next();
  601. String bookDetails = "<h1>The name of the book is <b>"
  602. +rs.getString("bookname") + "</b> and its cost is <b>" +rs.getString("bookprice") + "</b></h1>.";
  603. return bookDetails;
  604. }
  605. catch(Exception e)
  606. {
  607. System.out.println("Sorry failed to connect to the database.." + e.getMessage());
  608. }
  609. return null;
  610. }
  611. }
  612.  
  613. MUTUAL TOKEN
  614. 1. TokenServer.java
  615. import java.io.*; import java.net.*;
  616. public class TokenServer
  617. {
  618. public static void main(String agrs[])throws Exception {
  619. while(true)
  620. {
  621. Server sr=new Server(); sr.recPort(8000); sr.recData();
  622. }
  623. }
  624. }
  625. class Server
  626. {
  627. boolean hasToken=false; boolean sendData=false; int recport;
  628. void recPort(int recport)
  629. {
  630. this.recport=recport;
  631. }
  632. void recData()throws Exception
  633. {
  634. byte buff[]=new byte[256];
  635. 49
  636. Distributed Systems – Practical Manual – 2018-2019
  637. DatagramSocket ds; DatagramPacket dp; String str;
  638. ds=new DatagramSocket(recport);
  639. dp=new DatagramPacket(buff,buff.length); ds.receive(dp);
  640. ds.close();
  641. str=new String(dp.getData(),0,dp.getLength()); System.out.println("The message is "+str);
  642. }
  643. }
  644. 2. TokenClient1.java
  645. import java.io.*; import java.net.*;
  646. public class TokenClient1
  647. {
  648. public static void main(String arg[]) throws Exception
  649. {
  650. InetAddress lclhost; BufferedReader br; String str=""; TokenClient12 tkcl,tkser; boolean hasToken; boolean setSendData;
  651. while(true)
  652. {
  653. lclhost=InetAddress.getLocalHost(); tkcl = new TokenClient12(lclhost); tkser = new TokenClient12(lclhost); tkcl.setSendPort(9004); tkcl.setRecPort(8002); lclhost=InetAddress.getLocalHost(); tkser.setSendPort(9000);
  654. if(tkcl.hasToken == true)
  655. {
  656. YES/NO");
  657. System.out.println("Do you want to enter the Data -->
  658. br=new BufferedReader(new InputStreamReader(System.in)); str=br.readLine();
  659. if(str.equalsIgnoreCase("yes"))
  660. {
  661. System.out.println("ready to send"); tkser.setSendData = true; tkser.sendData();
  662. tkser.setSendData = false;
  663. 50
  664. Distributed Systems – Practical Manual – 2018-2019
  665. }
  666. else if(str.equalsIgnoreCase("no"))
  667. {
  668. }
  669. }
  670. else
  671. {
  672. tkcl.sendData(); tkcl.recData();
  673. System.out.println("ENTERING RECEIVING MODE..."); tkcl.recData();
  674. }
  675. }
  676. }
  677. }
  678. class TokenClient12
  679. {
  680. InetAddress lclhost; int sendport,recport;
  681. boolean hasToken = true; boolean setSendData = false; TokenClient12 tkcl,tkser;
  682. TokenClient12(InetAddress lclhost)
  683. {
  684. this.lclhost = lclhost;
  685. }
  686. void setSendPort(int sendport)
  687. {
  688. this.sendport = sendport;
  689. }
  690. void setRecPort(int recport)
  691. {
  692. this.recport = recport;
  693. }
  694. void sendData() throws Exception
  695. {
  696. BufferedReader br; String str="Token"; DatagramSocket ds; DatagramPacket dp;
  697. if(setSendData == true)
  698. {
  699. System.out.println("sending "); System.out.println("Enter the Data");
  700. 51
  701. Distributed Systems – Practical Manual – 2018-2019
  702. br=new BufferedReader(new InputStreamReader(System.in)); str = "ClientOne....." + br.readLine(); System.out.println("now sending");
  703. }
  704. ds = new DatagramSocket(sendport);
  705. dp = new DatagramPacket(str.getBytes(),str.length(),lclhost,sendport-1000); ds.send(dp);
  706. ds.close(); setSendData = false; hasToken = false;
  707. }
  708. void recData()throws Exception
  709. {
  710. String msgstr;
  711. byte buffer[] = new byte[256]; DatagramSocket ds; DatagramPacket dp;
  712. ds = new DatagramSocket(recport);
  713. dp = new DatagramPacket(buffer,buffer.length); ds.receive(dp);
  714. ds.close();
  715. msgstr = new String(dp.getData(),0,dp.getLength()); System.out.println("The data is "+msgstr);
  716. if(msgstr.equals("Token"))
  717. {
  718. hasToken = true;
  719. }
  720. }
  721. }
  722. 3. TokenClient2.java
  723. import java.io.*; import java.net.*;
  724. public class TokenClient2
  725. {
  726. static boolean setSendData ; static boolean hasToken ;
  727. public static void main(String arg[]) throws Exception
  728. {
  729. InetAddress lclhost; BufferedReader br; String str1; TokenClient21 tkcl; TokenClient21 ser;
  730. 52
  731. Distributed Systems – Practical Manual – 2018-2019
  732. while(true)
  733. {
  734. lclhost=InetAddress.getLocalHost(); tkcl = new TokenClient21(lclhost); tkcl.setRecPort(8004); tkcl.setSendPort(9002); lclhost=InetAddress.getLocalHost(); ser = new TokenClient21(lclhost); ser.setSendPort(9000);
  735. if(hasToken == true)
  736. {
  737. YES/NO");
  738. System.out.println("Do you want to enter the Data -->
  739. br=new BufferedReader(new InputStreamReader(System.in)); str1=br.readLine();
  740. if(str1.equalsIgnoreCase("yes"))
  741. {
  742. ser.setSendData = true; ser.sendData();
  743. }
  744. else if(str1.equalsIgnoreCase("no"))
  745. {
  746. }
  747. }
  748. else
  749. {
  750. tkcl.sendData(); hasToken=false;
  751. System.out.println("entering recieving mode"); tkcl.recData();
  752. hasToken=true;
  753. }
  754. }
  755. }
  756. }
  757. class TokenClient21
  758. {
  759. InetAddress lclhost; int sendport,recport;
  760. boolean setSendData = false; boolean hasToken = false; TokenClient21 tkcl; TokenClient21 ser;
  761. TokenClient21(InetAddress lclhost)
  762. {
  763. this.lclhost = lclhost;
  764. }
  765. 53
  766. Distributed Systems – Practical Manual – 2018-2019
  767. void setSendPort(int sendport)
  768. {
  769. this.sendport = sendport;
  770. }
  771. void setRecPort(int recport)
  772. {
  773. this.recport = recport;
  774. }
  775. void sendData() throws Exception
  776. {
  777. BufferedReader br; String str="Token"; DatagramSocket ds; DatagramPacket dp;
  778. if(setSendData == true)
  779. {
  780. System.out.println("Enter the Data");
  781. br=new BufferedReader(new InputStreamReader(System.in)); str = "ClientTwo....." + br.readLine();
  782. }
  783. ds = new DatagramSocket(sendport);
  784. dp = new DatagramPacket(str.getBytes(),str.length(),lclhost,sendport-1000); ds.send(dp);
  785. ds.close(); System.out.println("Data Sent"); setSendData = false;
  786. hasToken = false;
  787. }
  788. void recData()throws Exception
  789. {
  790. String msgstr;
  791. byte buffer[] = new byte[256]; DatagramSocket ds;
  792. DatagramPacket dp; ds = new DatagramSocket(recport); dp = new DatagramPacket(buffer,buffer.length); ds.receive(dp);
  793. ds.close(); msgstr = new
  794. String(dp.getData(),0,dp.getLength()); System.out.println("The data is "+msgstr); if(msgstr.equals("Token")) {
  795. hasToken = true;
  796. }
  797. }
  798. }
  799.  
  800.  
  801. CLOCK SYCHRONIZATION
  802. 1. SCServer.java
  803. import java.io.*; import java.net.*; import java.sql.*;
  804. public class SCServer
  805. {
  806. public static void main(String args[])throws Exception {
  807. InetAddress lclhost; lclhost=InetAddress.getLocalHost();
  808. long maxtime,skewtime,datatime; String maxtimestr,skewtimestr; BufferedReader br;
  809. ClntServer ser=new ClntServer(lclhost);
  810. System.out.println("Enter the maximum time"); br = new BufferedReader(new
  811. InputStreamReader(System.in)); maxtimestr=br.readLine();
  812. 56
  813. Distributed Systems – Practical Manual – 2018-2019
  814. System.out.println("Enter the maximum skew time"); br = new BufferedReader(new
  815. InputStreamReader(System.in)); skewtimestr=br.readLine();
  816. maxtime=Long.parseLong(maxtimestr); skewtime=Long.parseLong(skewtimestr);
  817. while(true)
  818. {
  819. }
  820. }
  821. }
  822. datatime = System.currentTimeMillis(); long G = datatime-maxtime-skewtime; System.out.println("G ="+G); ser.setTimeStamp(new Timestamp(G)); ser.recPort(8001);
  823. ser.recData();
  824. class ClntServer
  825. {
  826. InetAddress lclhost; int recport; Timestamp obtmp;
  827. ClntServer(InetAddress lclhost)
  828. {
  829. this.lclhost = lclhost;
  830. }
  831. void recPort(int recport)
  832. {
  833. this.recport = recport;
  834. }
  835. void setTimeStamp(Timestamp obtmp)
  836. {
  837. this.obtmp = obtmp;
  838. }
  839. void recData()throws Exception
  840. {
  841. String msgstr=""; DatagramSocket ds; DatagramPacket dp; BufferedReader br;
  842. byte buf[] = new byte[256];
  843. ds = new DatagramSocket(recport);
  844. dp = new DatagramPacket(buf,buf.length);
  845. 57
  846. Distributed Systems – Practical Manual – 2018-2019
  847. ds.receive(dp); ds.close();
  848. msgstr = new String(dp.getData(),0,dp.getLength()); System.out.println(msgstr);
  849. Timestamp obtmp = new Timestamp(Long.parseLong(msgstr)); if(this.obtmp.before(obtmp) == true)
  850. {
  851. }
  852. else
  853. {
  854. }
  855. }
  856. }
  857. System.out.println("The Message is accepted");
  858. System.out.println("The Message is rejected");
  859. 2. SCClient.java
  860. import java.io.*; import java.net.*;
  861. public class SCClient
  862. {
  863. public static void main(String args[])throws Exception {
  864. InetAddress lclhost; lclhost=InetAddress.getLocalHost();
  865. while(true)
  866. {
  867. }
  868. }
  869. }
  870. Client cntl=new Client(lclhost); cntl.sendPort(9001); cntl.sendData();
  871. class Client
  872. {
  873. InetAddress lclhost; int senport;
  874. Client(InetAddress lclhost)
  875. {
  876. this.lclhost=lclhost;
  877. }
  878. 58
  879. Distributed Systems – Practical Manual – 2018-2019
  880. void sendPort(int senport)
  881. {
  882. this.senport=senport;
  883. }
  884. void sendData()throws Exception
  885. {
  886. DatagramPacket dp; DatagramSocket ds; BufferedReader br;
  887. br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the data"); String str=br.readLine();
  888. ds = new DatagramSocket(senport);
  889. dp = new DatagramPacket(str.getBytes(),str.length(),lclhost,senport-1000); ds.send(dp);
  890. ds.close();
  891. }
  892. }
  893.  
  894. Write a program to implement two phase commit protocol.
  895.  
  896. Algorithm Used:
  897. A) Actions by the coordinator:
  898. Write START_2PC to local log;
  899. 60
  900. Distributed Systems – Practical Manual – 2018-2019
  901. Multicast VOTE_REQUEST to all participants; While not all votes have been collected {
  902. Wait for any incoming vote; If timeout
  903. {
  904. Write GLOBAL_ABORT to local log; Multicast GLOBAL_ABORT to all participants; Exit;
  905. }
  906. record vote;
  907. }
  908. If all participant sent VOTE_COMMIT and coordinator votes COMMIT
  909. {
  910. }
  911. else
  912. {
  913. }
  914. Write GLOBAL_COMMIT to local log; Multicast GLOBAL_COMMIT to all participants;
  915. Write GLOBAL_ABORT to local log; Multicast GLOBAL_ABORT to all participants;
  916. B) Actions by participants:
  917. Write INIT to local log;
  918. Wait for VOTE_REQUEST from coordinator; If timeout
  919. {
  920. write VOTE_ABORT to local log; exit;
  921. }
  922. if participant vote COMMIT
  923. {
  924. write VOTE_COMMIT to local log; send VOTE_COMMIT to coordinator; wait for DECISION from coordinator; if timeout
  925. {
  926. multicast DECISION_REQUEST to other participants; wait until DECISION is received;/*remain blocked*/ write DECISION to local log;
  927. }
  928. }
  929. else
  930. {
  931. if DECISION= = GLOBAL_COMMIT
  932. write GLOBAL_COMMIT to local log; else if DECISION= = GLOBAL_ABORT
  933. write GLOBAL_ABORT to local log;
  934. write VOTE_ABORT to local log;
  935. 61
  936. Distributed Systems – Practical Manual – 2018-2019
  937. send VOTE_ABORT to coordinator;
  938. }
  939. C) Action for handling decision request:
  940. While true
  941. {
  942. }
  943. Code:
  944. wait until any incoming DECISION_REQUEST is received;/*remain blocked*/ read most recently recorded STATES from the local log;
  945. if STATE= = GLOBAL_COMMIT
  946. send GLOBAL_COMMIT to requesting participants; else if STATE= =INIT or STATE= = GLOBAL_ABORT send
  947. GLOBAL_ABORT to requesting participants;
  948. else
  949. skip;/* participant remains blocked.*/
  950. 1. Server.java
  951. import java.io.*; import java.net.*; import java.util.*;
  952. public class Server
  953. {
  954. boolean closed=false,inputFromAll=false; List<clientThread> t;
  955. List<String> data;
  956. Server()
  957. {
  958. t = new ArrayList<clientThread>(); data= new ArrayList<String>();
  959. }
  960. public static void main(String args[])
  961. {
  962. Socket clientSocket = null; ServerSocket serverSocket = null; int port_number=1111;
  963. Server ser=new Server(); try
  964. {
  965. serverSocket = new ServerSocket(port_number);
  966. }
  967. catch (IOException e)
  968. {
  969. System.out.println(e);
  970. }
  971. while(!ser.closed)
  972. {
  973. 62
  974. Distributed Systems – Practical Manual – 2018-2019
  975. }
  976. try
  977. {
  978. try
  979. {
  980. }
  981. clientSocket = serverSocket.accept();
  982. clientThread th=new clientThread(ser,clientSocket); (ser.t).add(th);
  983. System.out.println("\nNow Total clients are : "+(ser.t).size()); (ser.data).add("NOT_SENT");
  984. th.start();
  985. catch (IOException e)
  986. {
  987. }
  988. serverSocket.close();
  989. }
  990. catch(Exception e1)
  991. {
  992. }
  993. }
  994. }
  995. class clientThread extends Thread
  996. {
  997. DataInputStream is = null; String line;
  998. String destClient=""; String name; PrintStream os = null;
  999. Socket clientSocket = null; String clientIdentity; Server ser;
  1000. public clientThread(Server ser,Socket clientSocket)
  1001. {
  1002. this.clientSocket=clientSocket; this.ser=ser;
  1003. }
  1004. public void run()
  1005. {
  1006. try
  1007. {
  1008. is = new DataInputStream(clientSocket.getInputStream()); os = new PrintStream(clientSocket.getOutputStream()); os.println("Enter your name."); name = is.readLine(); clientIdentity=name;
  1009. 63
  1010. Distributed Systems – Practical Manual – 2018-2019
  1011. os.println("Welcome "+name+" to this 2 Phase Application.\nYou will receive a vote Request now...");
  1012. os.println("VOTE_REQUEST\nPlease enter COMMIT or ABORT to
  1013. proceed : ");
  1014. for(int i=0; i<(ser.t).size(); i++)
  1015. {
  1016. if((ser.t).get(i)!=this)
  1017. {
  1018. ((ser.t).get(i)).os.println("---A new user
  1019. "+name+" entered the Appilcation---");
  1020. }
  1021. }
  1022. while (true)
  1023. {
  1024. line = is.readLine(); if(line.equalsIgnoreCase("ABORT"))
  1025. {
  1026. System.out.println("\nFrom '"+clientIdentity+"' :
  1027. ABORT\n\nSince aborted we will not wait for inputs from other clients.");
  1028. System.out.println("\nAborted....");
  1029. for(int i=0; i<(ser.t).size(); i++)
  1030. {
  1031. ((ser.t).get(i)).os.println("GLOBAL_ABORT");
  1032. ((ser.t).get(i)).os.close();
  1033. ((ser.t).get(i)).is.close();
  1034. }
  1035. break;
  1036. }
  1037. if(line.equalsIgnoreCase("COMMIT"))
  1038. {
  1039. COMMIT");
  1040. System.out.println("\nFrom '"+clientIdentity+"' :
  1041. if((ser.t).contains(this))
  1042. {
  1043. (ser.data).set((ser.t).indexOf(this), "COMMIT"); for(int j=0;j<(ser.data).size();j++) {
  1044. if(!(((ser.data).get(j)).equalsIgnoreCase("NOT_SENT")))
  1045. {
  1046. }
  1047. else
  1048. {
  1049. ser.inputFromAll=true; continue;
  1050. ser.inputFromAll=false; System.out.println("\nWaiting for inputs from other clients.");
  1051. 64
  1052. Distributed Systems – Practical Manual – 2018-2019
  1053. break;
  1054. }
  1055. }
  1056. if(ser.inputFromAll)
  1057. {
  1058. System.out.println("\n\nCommited....");
  1059. for(int i=0; i<(ser.t).size(); i++)
  1060. {
  1061. ((ser.t).get(i)).os.println("GLOBAL_COMMIT");
  1062. }
  1063. }//if t.contains
  1064. }//commit
  1065. }//while
  1066. ser.closed=true; clientSocket.close();
  1067. }
  1068. break;
  1069. ((ser.t).get(i)).os.close();
  1070. ((ser.t).get(i)).is.close();
  1071. }
  1072. catch(IOException e)
  1073. {
  1074. };
  1075. }
  1076. }
  1077. 2. Client.java
  1078. import java.io.*; import java.net.*;
  1079. public class Client implements Runnable
  1080. {
  1081. static Socket clientSocket = null; static PrintStream os = null; static DataInputStream is = null;
  1082. static BufferedReader inputLine = null; static boolean closed = false;
  1083. public static void main(String[] args)
  1084. {
  1085. int port_number=1111; String host="localhost"; try
  1086. {
  1087. clientSocket = new Socket(host, port_number); inputLine = new BufferedReader(new
  1088. InputStreamReader(System.in));
  1089. 65
  1090. Distributed Systems – Practical Manual – 2018-2019
  1091. os = new PrintStream(clientSocket.getOutputStream());
  1092. is = new DataInputStream(clientSocket.getInputStream());
  1093. }
  1094. catch (Exception e)
  1095. {
  1096. System.out.println("Exception occurred : "+e.getMessage());
  1097. }
  1098. if (clientSocket != null && os != null && is != null)
  1099. {
  1100. try
  1101. {
  1102. new Thread(new Client()).start();
  1103. while (!closed)
  1104. {
  1105. os.println(inputLine.readLine());
  1106. }
  1107. os.close();
  1108. is.close();
  1109. clientSocket.close();
  1110. }
  1111. catch (IOException e)
  1112. {
  1113. System.err.println("IOException: " + e);
  1114. }
  1115. }
  1116. }
  1117. public void run()
  1118. {
  1119. String responseLine;
  1120. try
  1121. {
  1122. while ((responseLine = is.readLine()) != null)
  1123. {
  1124. System.out.println("\n"+responseLine);
  1125. if
  1126. (responseLine.equalsIgnoreCase("GLOBAL_COMMIT")==true ||
  1127. responseLine.equalsIgnoreCase("GLOBAL_ABORT")==true )
  1128. {
  1129. break;
  1130. }
  1131. }
  1132. closed=true;
  1133. }
  1134. catch (IOException e)
  1135. {
  1136. System.err.println("IOException: " + e);
  1137. }
  1138. }
  1139. }
  1140.  
  1141. O/P- JAVA SERVER
  1142. JAVA CLIENT(3TIMES)
  1143.  
  1144.  
  1145. RPC EXECUTION
  1146.  
  1147. JAVAC CLIENT
  1148. JAVA CLIENT
  1149. JAVA RPCServer
  1150. 1)
  1151. TCP(Transmission Control Protocol)
  1152.  
  1153. Package used for Socket Programming Using TCP / UDP
  1154.  
  1155.  
  1156. import java.io.*;
  1157. import java.net.*;
  1158.  
  1159.  
  1160.  
  1161. Connection Establishment Code.
  1162. Server:
  1163. try
  1164. {
  1165. int port = 8888;
  1166. ServerSocket ss= new ServerSocket(port);
  1167. System.out.println("Waiting for Client");
  1168. Socket s = ss.accept();
  1169.  
  1170. }
  1171. catch (Exception e)
  1172. {
  1173. System.out.println("Error :" + e);
  1174. }
  1175.  
  1176. Client
  1177. try
  1178. {
  1179. int port = 8888;
  1180. InetAddress addr = InetAddress.getLocalHost();
  1181. Socket s = new Socket(addr, port);
  1182. System.out.println("Connection is established");
  1183.  
  1184.  
  1185. }
  1186. catch (Exception e)
  1187. {
  1188. System.out.println("Error :" + e);
  1189. }
  1190.  
  1191.  
  1192.  
  1193.  
  1194. User Input In TCP/UDP(BufferedReader with System.in):
  1195.  
  1196.  
  1197. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  1198. System.out.println("Enter The Number :");
  1199. String req = br.readLine();
  1200.  
  1201.  
  1202. Send Data to Socket In TCP
  1203.  
  1204. PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
  1205. pw.println(str);
  1206. pw.flush();
  1207.  
  1208.  
  1209. Receive Data from Socket in TCP(BufferedReader with getInputStream()).
  1210.  
  1211. BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
  1212. String str = br.readLine();
  1213. System.out.println("Request From The Client :" + str);
  1214.  
  1215.  
  1216. UDP(User Datagram Protocol)
  1217. DatagramSocket Code.
  1218. Server
  1219. try
  1220. {
  1221. int port = 6666;
  1222. DatagramSocket ds = new DatagramSocket(port);
  1223. System.out.println("Waiting for Client");
  1224. }
  1225. catch (Exception e)
  1226. {
  1227. System.out.println("Error :" + e);
  1228. }
  1229. Client
  1230. try
  1231. {
  1232. int port = 5555;
  1233. DatagramSocket ds = new DatagramSocket(port);
  1234. }
  1235. catch (Exception e)
  1236. {
  1237. System.out.println("Error :" + e);
  1238. }
  1239.  
  1240.  
  1241. To Send Data In UDP
  1242.  
  1243. byte b[] = new byte[1024];
  1244. b = req.getBytes();
  1245. DatagramPacket dp1 = new DatagramPacket(b,b.length,InetAddress.getLocalHost(),6666);
  1246. ds.send(dp1);
  1247.  
  1248. To Receive Data In Data
  1249.  
  1250. byte b[] = new byte[1024];
  1251. DatagramPacket dp1 = new DatagramPacket(b, b.length);
  1252. ds.receive(dp1);
  1253. String str = new String(dp1.getData(),0,dp1.getLength());
  1254.  
  1255.  
  1256.  
  1257. RMI(Remote Method Invocation)
  1258. Packages
  1259. import java.io.*;
  1260. import java.net.*;
  1261. import java.rmi.*;
  1262. import java.rmi.server.*;
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268. Step1 : Interface File(Mathoptr.java)
  1269. import java.io.*;
  1270. import java.net.*;
  1271. import java.rmi.*;
  1272. import java.rmi.server.*;
  1273. public interface MathOptr extends Remote
  1274. {
  1275. public double square(int num) throws Exception;
  1276. public double squareroot(int num) throws Exception;
  1277. public double cube(int num) throws Exception;
  1278. public double cuberoot(int num) throws Exception;
  1279. }
  1280.  
  1281.  
  1282. Step 2 : Implementation File(MathOptrImpl.java)
  1283. import java.io.*;
  1284. import java.net.*;
  1285. import java.rmi.*;
  1286. import java.rmi.server.*;
  1287. public class MathOptrImpl extends UnicastRemoteObject implements MathOptr
  1288. {
  1289. public MathOptrImpl() throws Exception
  1290. {
  1291. super();
  1292. }
  1293.  
  1294. public double square(int num) throws Exception
  1295. {
  1296. return (num*num);
  1297. }
  1298. public double squareroot(int num) throws Exception
  1299. {
  1300. return(Math.sqrt(num));
  1301. }
  1302. public double cube(int num) throws Exception
  1303. {
  1304. return(num*num*num);
  1305. }
  1306. public double cuberoot(int num) throws Exception
  1307. {
  1308. return(Math.cbrt(num));
  1309. }
  1310. }
  1311.  
  1312.  
  1313. Step 3 : Server File(MathOptrServer.java)
  1314. import java.io.*;
  1315. import java.net.*;
  1316. import java.rmi.*;
  1317. import java.rmi.server.*;
  1318. public class MathOptrServer
  1319. {
  1320. public static void main(String args[]) throws Exception
  1321. {
  1322.  
  1323. MathOptrImpl obj = new MathOptrImpl();
  1324. Naming.rebind("abc",obj);
  1325.  
  1326. System.out.println("Waiting For Client");
  1327. }
  1328. }
  1329.  
  1330. Step 4: Client File(MathOptrClient.java)
  1331. import java.io.*;
  1332. import java.net.*;
  1333. import java.rmi.*;
  1334. import java.rmi.server.*;
  1335. public class MathOptrClient
  1336. {
  1337. public static void main(String args[]) throws Exception
  1338. {
  1339. MathOptr obj = (MathOptr) Naming.lookup("abc") ;
  1340.  
  1341.  
  1342. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  1343. System.out.println("Enter The Number :");
  1344. String req = br.readLine();
  1345. int num = Integer.parseInt(req);
  1346.  
  1347.  
  1348. System.out.println("Square :" + obj.square(num));
  1349. System.out.println("Square Root :" + obj.squareroot(num));
  1350. System.out.println("Cube :" + obj.cube(num));
  1351. System.out.println("Cube Root :" + obj.cuberoot(num));
  1352.  
  1353. }
  1354. }
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360. Step 5: Compile all the files(javac *.java);
  1361. Step6 : Start rmi registry(Start rmiregistry)
  1362.  
  1363. Step7 : Generate Stub File(Rmic MathOptrImpl)
  1364.  
  1365. Step8 : Run Server file(java MathOptrServer)
  1366. Step 9: Run Client(java MathOptrClient)
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377. NFS Configuration
  1378.  
  1379. We need 2 linux machine > Power ON the machines
  1380.  
  1381. SERVER
  1382. Right click > open terminal>
  1383.  
  1384. Step 1: Set IP addr(vim /etc/sysconfig/network-scripts/ifcfg-eth0
  1385. then press Enter
  1386. After entering press > i
  1387. DEVICE=eth0
  1388. ONBOOT=yes
  1389. BOOTPROTO=static
  1390. IPADDR=192.168.1.10
  1391. NETMASK=255.255.255.0
  1392. (esc+shift+: wq)
  1393.  
  1394. # service network restart
  1395. # ifconfig(to check ipaddress changed)
  1396.  
  1397. Step2: #service iptables stop
  1398. # service iptables status
  1399. Step 3: Install the req packages
  1400. # cd /media/RHEl(press TAB)
  1401. # rpm -ivh --force --nodeps nfs*
  1402. Step 4: mkdir /nfsserver
  1403. # cd /nfsserver/
  1404. (nfsserver) # touch f1 f2 f3 f4
  1405. # ls
  1406. # chmod -R 777 /nfsserver/
  1407. # ls (f1 f2 changs to green color)
  1408. Step 4:# vim /etc/exports
  1409. /nfsserver *(rw,sync)
  1410. Esc+shift+: )wq
  1411. # exportfs -a (actual export)
  1412. # exportfs -v(to view the exported file system)
  1413. Step 5: # service nfs restart(if failed run again command)
  1414.  
  1415. Client
  1416. Step1: Set IP addr(vim /etc/sysconfig/network-scripts/ifcfg-eth1 then press Enter
  1417. After entering press > i
  1418. DEVICE=eth1
  1419. ONBOOT=yes
  1420. BOOTPROTO=static
  1421. IPADDR=192.168.1.11
  1422. NETMASK=255.255.255.0
  1423. (esc+shift+: wq)
  1424. # service network restart
  1425. # ifconfig(to check ipaddress changed)
  1426. Step2: #service iptables stop
  1427. # service iptables status
  1428. Step 3: Install the req packages
  1429. # cd /media/RHEl(press TAB)/P(TAB)
  1430. # rpm -ivh --force --nodeps nfs*
  1431. Step 3: mkdir /client
  1432. # ls /client/(will be empty)
  1433. # mount 192.168.1.10:/nfsserver /client
  1434. # ls /client/(to check)
  1435. To write contenrt
  1436. # cat >> f1
  1437. Hgfdiagfjkfghiusjkvsid
  1438.  
  1439.  
  1440.  
  1441. Fact
  1442. Int f=1;
  1443. {f=f*I;}return f;
  1444.  
  1445. Rev
  1446. Int rev=0;
  1447. While(num num me kola 0){Int r=num%10;
  1448. Rev = rev*10+r;num=num/10;}return rev;
  1449.  
  1450.  
  1451.  
  1452. Even odd
  1453. {
  1454. If(num%2==0)
  1455. {return"the number is even";
  1456. }
  1457. else{ return "odd";
  1458. }
  1459.  
  1460.  
  1461. Prime
  1462.  
  1463. {
  1464. Boolean flag=false;
  1465. for(Int I=2;iless num/2;++I)
  1466. {
  1467. If(num%==0)
  1468. { flag=true}}if(!flag){return"prime"}
  1469. Else{return "not prime";}}
  1470.  
  1471.  
  1472.  
  1473. Vowels
  1474. {
  1475. If(name.equals('a') || name.equals('e') || name.equals('i') || name.equals('o') || name.equals('u') )
  1476. {Return "vowels";}
  1477. Else
  1478. {Return"constants";
  1479. }
  1480. }
Add Comment
Please, Sign In to add comment