You are on page 1of 4

Object- Simulate Sliding Window Protocol in C++. Program#include<iostream.h> #include<conio.h> #include<dos.

h> int a[20]; void layer() { gotoxy(15,10); cout<<"SLIDING WINDOW REPRESENTATION"; gotoxy(5,13); cout<<"Sender"; gotoxy(40,13); cout<<"Receiver"; } void blink(int data,int sa,int da) { int i,j; for(i=5;i<40;i++) { layer(); gotoxy(i,15); cout<<"ENQ"; delay(200); clrscr(); } for(j=1;j<=data;j++) { for(i=5;i<40;i++) { layer(); gotoxy(i,15); cout<<"("<<sa<<",DATA"<<j<<","<<da<<")"; delay(200); clrscr(); } } for(j=1;j<=data+1;j++) { for(i=40;i>1;i--) { layer(); gotoxy(i,17); if(j==1) cout<<"(ACK,ENQ)";

else cout<<"(ACK,DATA"<<j<<")"; delay(200); clrscr(); } } for(i=5;i<40;i++) { layer(); gotoxy(i,15); cout<<"EOT"; delay(200); clrscr(); } for(i=40;i>1;i--) { layer(); gotoxy(i,17); cout<<"(ACK,EOT)"; delay(200); clrscr(); } } void main() { clrscr(); int data,s,d; cout<<"enter the no of data packet u want to send"; cin>>data; cout<<"enter sourse Add"; cin>>s; cout<<"enter destination Add"; cin>>d; blink(data,s,d); }

Practical No-4 Object- Implement Java RMI mechanism for accessing method of Remote System. Program1.Create the interfaceimport java.rmi.*; public interface Hello extends Remote { public String getGreeting() throws RemoteException; } 2. Define a class that implements this interface. import java.rmi.*; import java.rmi.server.*; public class HelloImpl extends UnicastRemoteObject implements Hello { public HelloImpl() throws RemoteException { //No action needed here. } public String getGreeting() throws RemoteException { return ("Hello there!"); } } 3. Create the server process. import java.rmi.*; public class HelloServer { private static final String HOST = "localhost"; public static void main(String[] args) throws Exception { //Create a reference to an implementation object... HelloImpl temp = new HelloImpl(); //Create the string URL holding the object's name... String rmiObjectName = "rmi://" + HOST + "/Hello"; //(Could omit host name here, since 'localhost' would be assumed by default.) //'Bind' the object reference to the name... Naming.rebind(rmiObjectName,temp); //Display a message so that we know the process has been completed... System.out.println("Binding complete...\n"); } }

4. Create the client process. import java.rmi.*; public class HelloClient { private static final String HOST = "localhost"; public static void main(String[] args) { try { //Obtain a reference to the object from the registry and typecast it into the appropriate //type... Hello greeting =(Hello)Naming.lookup("rmi://"+ HOST + "/Hello"); //Use the above reference to invoke the remote object's method... System.out.println("Message received: "+ greeting.getGreeting()); } catch(ConnectException conEx) { System.out.println("Unable to connect to server!"); System.exit(1); } catch(Exception ex) { ex.printStackTrace(); System.exit(1); } } }

You might also like