33
Program no. 1 Objective : WAP to simulate the functionality of Lamport’s logical clock in C. Theory : Lamport proposed this scheme to provide ordering of events in a distributed environment using logical clocks, as it is impossible to have perfectly synchronized clocks and global time in a distributed system. Lamport introduced a system of logical clocks in order to make the “happened before” relation possible. It works like this: Each process P i in the system has its own clock C i . C i can be looked at as a function that assigns a number, C i (a) to an event a. This is the timestamp of the event a in process P i . These numbers are not in any way related to physical time -- that is why they are called logical clocks. These are generally implemented using counters, which increase each time an event occurs. Generally, an event's timestamp is the value of the clock at that time it occur. Implementation Rules Required : Clock C i is incremented for each event: C i := C i + d (d > 0) if a is the event of sending a message from one process to another, then the receiver sets its clock to the max of its current clock and the sender's clock - that is, C j := max(C j , t m + d) (d > 0) . Coding : #include<stdio.h> #include<conio.h> long p1(int); long p2(int); long p3(int); long p4(int);

DS file (1)

Embed Size (px)

Citation preview

Page 1: DS file (1)

Program no. 1

Objective : WAP to simulate the functionality of Lamport’s logical clock in C.

Theory :

Lamport proposed this scheme to provide ordering of events in a distributed environment using logical clocks, as it is impossible to have perfectly synchronized clocks and global time in a distributed system.

Lamport introduced a system of logical clocks in order to make the “happened before” relation possible. It works like this: Each process Pi in the system has its own clock Ci. Ci can be looked at as a function that assigns a number, Ci(a) to an event a. This is the timestamp of the event a in process Pi. These numbers are not in any way related to physical time -- that is why they are called logical clocks. These are generally implemented using counters, which increase each time an event occurs. Generally, an event's timestamp is the value of the clock at that time it occur.

Implementation   Rules   Required :

Clock Ci is incremented for each event: Ci := Ci + d (d > 0) if a is the event of sending a message from one process to another, then the

receiver sets its clock to the max of its current clock and the sender's clock - that is, Cj := max(Cj, tm + d) (d > 0) .

Coding :

#include<stdio.h>#include<conio.h>long p1(int);long p2(int);long p3(int);long p4(int);void main(){ int k; clrscr(); printf(“Enter the process no : “); scanf(“%d”,&k); while(!kbhit()) { if(k==1) p1(1);

Page 2: DS file (1)

if(k==2) p2(1); if(k==3) p3(1); if(k==4) p4(1); } getch(); printf(“\n Logical Clock \n”); printf(“P1 : %ld \n P2 : %ld\n P3 : %ld \n P4 : %ld \n”,p1(0), p2(0), p3(0), p4(0)); getch();}long p1(int i){ static long a=0; if(i==1) { a++; p2(1); return 1; } else return a;}long p2(int i){ static long b=0; if(i==1) { b++; p3(1); p4(1); return 1; } else return b;}long p3(int i){ static long c=0; if(i==1) { c++; return 1; }

Page 3: DS file (1)

else return c;}long p4(int i){ static long d=0; if(i==1) { d++; p3(1); return 1; } else return d;}

OUTPUT:

Enter the process no :1Logical ClockP1: 8P2:7P3:12P4:9

Page 4: DS file (1)

Program no. 2

Objective : WAP to implement Vector clock in C.

Theory :

Vector clocks are an algorithm for generating a partial ordering of events in a distributed system. A vector clock of a system of N processes is an array/vector of N logical clocks, one clock per process; a local "smallest possible values" copy of the global clock-array is kept in each process, with the following rules for clock updates:

Initially all clocks are zero. Each time a process experiences an internal event, it increments its

own logical clock in the vector by one. Each time a process prepares to send a message, it increments its

own logical clock in the vector by one and then sends its entire vector along with the message being sent.

Each time a process receives a message, it increments its own logical clock in the vector by one and updates each element in its vector by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element).

Coding : #include<stdio.h>#include<conio.h>#include<stdlib.h>long *p1(int i, long *comp);long *p2(int i, long *comp);long *p3(int i, long *comp);void main(){ long start[]={0,0,0},*vector; clrscr(); while(!kbhit())

Page 5: DS file (1)

{ p1(1,&start[0]); } printf(“\n Process vector \n “); vector=p1(0,&start[0]); printf(“p1[%ld%ld%ld]\n,*vector,*(vector +1),*(vector+2)); vector=p2(0,&start[0]); printf(“p2[%ld%ld%ld]\n,*vector,*(vector +1),*(vector+2)); vector=p3(0,&start[0]); printf(“p3[%ld%ld%ld]\n,*vector,*(vector +1),*(vector+2)); } long *p1(int i, long *comp){ static long a[]={0,0,0}; int next; if(i==1) { a[0]++; if(*(comp+1)>a[1]) a[1]=*(comp+1); if(*(comp+2)>a[2]) a[2]=*(comp+2); next=random(2); if(next==0) p2(1,&a[0]); else if(next==1) p3(1,&a[0]); return(&a[0]); } else return(&a[0]);}long *p2(int i, long *comp){ static long b[]={0,0,0}; int next; if(i==1) { b[i]++; if(*(comp)>b[0]) b[0]=*(comp); if(*(comp+2)>b[2]) b[2]=*(comp+2); next=random(2); if(next==0) p1(1,&b[0]);

Page 6: DS file (1)

else if(next==1) p3(1,&b[0]); return(&b[0]); } else return(&b[0]);}long *p3(int i, long *comp){ static long c[]={0,0,0}; int next; if(i==1) { c[2]++; if(*(comp)>c[0]) c[0]=*(comp); if(*(comp+1)>c[1]) c[1]=*(comp+1); next=random(2); if(next==0) p1(1,&c[0]); return(&c[0]); } else return(&c[0]);}

OUTPUT:

Process vectorp1[7,5,3]p2[6,6,3]p3[2,4,6]

Page 7: DS file (1)

Program no. 3

Objective: WAP to implement simulation of Distributed mutual exclusion in C.

Theory :

Mutual exclusion ensures that concurrent processes make a serialized access to shared resources or data. In a distributed system neither shared variables (semaphores) nor a local kernel can be used in order to implement mutual exclusion! Thus, mutual exclusion has to be based exclusively on message passing.

Basic requirements for a mutual exclusion mechanism:

• safety: at most one process may execute in the critical section (CS) at a time;

• liveness: a process requesting entry to the CS is eventually granted it. Liveness implies freedom of deadlock and starvation.

There are two basic approaches to distributed mutual exclusion:

1. Non-token-based: each process freely and equally competes for the right to use the shared resource; requests are arbitrated by a central control site or by distributed agreement.

2. Token-based: a logical token representing theaccess right to the shared resource is passed in a regulated fashion among the processes; whoever holds the token is allowed to enter the critical section.

Page 8: DS file (1)

Coding :

#include <stdio.h>#include <unistd.h>#include <common/defs.h>#include <common/init.h>#include <common/util.h>#include <common/net.h>uint64 proc_id = 0; link_info_t * nodes = NULL; bool_t exit_request = FALSE;static char * fname = NULL;int testfunc1(void * cookie) { uint8 *buff = NULL; int len = 0; dbg_msg("A message arrived from the depths of internet! cookie='%s'", (char *)cookie); dbg_msg("Go check the socket! :p"); dme_recv_msg(&buff, &len); dbg_msg("Oh goodie! recieved message[%d]: %s", len, buff); return 0;}int main(int argc, char *argv[]){ FILE *fh; int res = 0; if (0 != (res = parse_params(argc, argv, &proc_id, &fname))) { dbg_err("parse_args() returned nonzero status:%d", res); goto end; } if (0 != (res = parse_file(fname, proc_id, &nodes))) { dbg_err("parse_file() returned nonzero status:%d", res); goto end; } dbg_msg("nodes has %d elements", sizeof(nodes)); if (0 != (res = open_listen_socket(proc_id, nodes))) { dbg_err("open_listen_socket() returned nonzero status:%d", res); goto end; } if (0 != (res = init_handlers(nodes[proc_id].sock_fd))) {

Page 9: DS file (1)

dbg_err("init_handlers() returned nonzero status"); goto end; } register_event_handler(DME_EV_MSG_IN, testfunc1); register_event_handler(20, testfunc1); dbg_msg("Sleeping 2 secs before delivering event DME_EV_MSG_IN"); sleep(2); deliver_event(DME_EV_MSG_IN, "GREAT SUCCESS"); deliver_event(DME_EV_MSG_IN, "O'rly ?"); deliver_event(20, "This should generate 'how we got here???' msg"); dbg_msg("Sleeping 5 secs before engaging in network communication. Wait for other nodes to init"); sleep(5); dbg_msg("Sending a tex to another process id"); char * buff[256]; sprintf(buff, "\n\n\n\t\t *** This is a message from peer process %d ****\n\n\n\n", proc_id); dme_send_msg((proc_id +1) % 2, buff, strlen(buff)); while(!exit_request) { wait_events(); } end; if (nodes[proc_id].sock_fd > 0) { close(nodes[proc_id].sock_fd); } safe_free(nodes); safe_free(nodes); return res;}

Page 10: DS file (1)

Program No. 4

Objective : Implement a Distributed Chat Server using TCP sockets in java.

Theory :

In the chat system, we use TCP (Transmission Control Protocol)for the control messages between chat client and server and we use UDP (User Datagram Protocol) for the public chat messages between chat client and chat server.

TCP is a connection oriented reliable protocol. TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. Hence, it is very useful for sending the control messages.

Coding :

Server.java

import java.net.*;

Page 11: DS file (1)

import java.io.*;public class server{ public static void main(Strings args[])throws IOException { ServerSocket s1=null; try { s1=new ServerSocket(98); } catch(Exception.e) { System.out.println(“Port not found”); e.printStackTrace(); } Socket c=null; try { c=s1.accept(); System.out.println(“Connection from”+c); } catch(Exception.e) { System.out.println(“Not accepted”); e.printStackTrace(); } PrintWriter out=new PrintWriter(c.getOutputStream(),true); BufferedReader in=new BufferedReader(new InputStreamReader(c.getInputStream())); String I; BufferedReader sin=new BufferedReader(new InputStreamReader(System.in)); System.out.println(“I am ready to type now”); while((l=sin.readLine())!=null) { out.println(l); } out.close(); sin.close(); c.close(); s1.close(); }}

Client.java

Page 12: DS file (1)

import java.net.*;import java.io.*;public class server{ public static void main(Strings args[])throws IOException { Socket s=null; try { s=new Socket(lnetAddress.getLocalHost(),98); b=new BufferedReader(new InputStreamReader (s.getInputStream())); } catch(Exception.e) { System.out.println(“I do not host”); e.printStackTrace(); } String inp; while((inp=b.readLine()!=null) { System.out.println(inp); } b.close(); s.close(); }}

Running the Application :

Open two cmd and follow these1.java Server2.java client

Output

C:\Windows\RND\Java\Networking\ChatServer>java serverConnection from Socket[addr=/127.0.0.1,port=1120,localport=98]I am ready type nowHello how r u? dude…C:\Windows\RND\Java\Networking\ChatServer>java clientHello how r u? dude…

Page 13: DS file (1)

Program no. 5

Objective : Implement ‘Java RMI’ mechanism for accessing methods of remote system.

Theory :

The Java Remote Method Invocation or Java RMI, extends the java object model to provide support for distributed object in java language. It allows objects to invoke methods on remote objects using the same syntax as for local invocation. Also type checking applies equally to remote application as to local ones. But, an object making a remote invocation is aware that its target is remote as it has to handle RemoteExceptions and the implementor of remote object should be aware that it is remote as it has to implement RemoteInterface.

Page 14: DS file (1)

Java RMI facilitates object function calls between Java Virtual Machines (JVMs). JVMs can be located on separate computers - yet one JVM can invoke methods belonging to an object stored in another JVM. Methods can even pass objects that a foreign virtual machine has never encountered before, allowing dynamic loading of new classes as required. 

Coding :

Remote Object Interface :

import java.rmi.*;

public interface RMIExample extends Remote{ public boolean PostMsg(String strMsg) throws RemoteException; public long Factorial(long lVal) throws RemoteException;}

Server Side Code :

import java.rmi.*;import java.rmi.server.UnicastRemoteObject;import java.io.*;public class RMIExampleImpl extends UnicastRemoteObject implements RMIExample{ protected static String m_strName; public RMIExampleImpl() throws RemoteException { super(); } public boolean PostMsg(String strMsg) throws RemoteException { System.out.println("Server: PostMsg() invoked..."); System.out.println("Server: Message > " + strMsg); return true; } public long Factorial(long lVal) throws RemoteException { long lRes = FactorialEx(lVal); System.out.println("Server: Factorial() invoked..."); System.out.println("Server: Factorial("+lVal+") = " + lRes); return lRes; } protected long FactorialEx(long lVal)

Page 15: DS file (1)

{ if (lVal <= 1) return 1; else return lVal * FactorialEx(lVal-1); } public static void main(String argv[]) { try { m_strName = "TheRMIExample"; System.out.println("Server: Registering RMIExampleImpl as \"" + m_strName +"\""); RMIExampleImpl Example = new RMIExampleImpl(); Naming.rebind(m_strName, Example); System.out.println("Server: Ready..."); } catch (Exception e) { System.out.println("Server: Failed to register RMIExampleImpl: " + e); } }}

Client Side Code :

import java.rmi.*;import java.rmi.server.*;public class RMIClient { public static void main(String argv[]) { if (argv.length < 2) { System.out.println("Usage: java RMIClient [-m \"MESSAGE\"] [-f INTEGER]"); System.exit(1); } boolean bMessage = false; boolean bFactorial = false; String strMsg = "No message."; long lVal = 1; for (int i=0; i<argv.length; i++) { if (argv[i].equals("-m")) {

Page 16: DS file (1)

bMessage = true; strMsg = argv[++i]; } if (argv[i].equals("-f")) { bFactorial = true; lVal = Long.parseLong(argv[++i]); } } System.setSecurityManager(new RMISecurityManager()); String strName = "rmi://wpi.wpi.edu/TheRMIExample"; System.out.println("Client: Looking up " + strName + "..."); RMIExample RemRMIExample = null; try { RemRMIExample = (RMIExample)Naming.lookup(strName); } catch (Exception e) { System.out.println("Client: Exception thrown looking up " + strName); System.exit(1); } if (bMessage) { try { if (!RemRMIExample.PostMsg(strMsg)) System.out.println("Client: Remote PostMsg() call failed."); } catch (Exception e) { System.out.println("Client: Exception thrown calling PostMsg()."); System.exit(1); } } if (bFactorial) { try { long lRes = RemRMIExample.Factorial(lVal); System.out.println("Client: Factorial(" + lVal + ") = " + lRes); } catch (Exception e) { System.out.println("Client: Excpetion thrown calling Factorial()."); System.exit(1);

Page 17: DS file (1)

} } }}

Running the application :

C:\Windows\RND\Java\Networking\RMI>java RMIExampleImpl.javaC:\Windows\RND\Java\Networking\RMI>java RMIClient

Output

If all goes well yo see the following output :

19183

Program no. 6

Objective : WAP to implement simulation of Balanced Sliding Window Protocol in C.

Page 18: DS file (1)

Theory :

A sliding window protocol is a feature of packet-based data transmission protocols. Sliding window protocols are used where reliable in-order delivery of packets is required, such as in the Data Link Layer (OSI model) as well as in the Transmission Control Protocol (TCP).Conceptually, each portion of the transmission is assigned a unique consecutive sequence number, and the receiver uses the numbers to place received packets in the correct order, discarding duplicate packets and identifying missing ones. The problem with this is that there is no limit of the size of the sequence numbers that can be required.By placing limits on the number of packets that can be transmitted or received at any given time, a sliding window protocol allows an unlimited number of packets to be communicated using fixed-size sequence numbers.For the highest possible throughput, it is important that the transmitter is not forced to stop sending by the sliding window protocol earlier than one round-trip delay time (RTT). The limit on the amount of data that it can send before stopping to wait for an acknowledgment should be larger than the bandwidth-delay product of the communications link. If it is not, the protocol will limit the effective bandwidth of the link.

Coding :

SERVER :

#include<stdio.h> #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<arpa/inet.h> #define SIZE 4 void main() { int sfd,lfd,len,i,j,status; char str[20],frame[20],temp[20],ack[20]; struct sockaddr_in saddr,caddr; sfd=socket(AF_INET,SOCK_STREAM,0); if(sfd<0) perror("ERROR"); bzero(&saddr,sizeof(saddr)); saddr.sin_family=AF_INET; saddr.sin_addr.s_addr=htonl(INADDR_ANY);

Page 19: DS file (1)

saddr.sin_port=htons(4980); if(bind(sfd,(struct sockaddr*)&saddr,sizeof(saddr))<0) perror("Bind Error"); listen(sfd,5); len=sizeof(&caddr); lfd=accept(sfd,(struct sockaddr*)&caddr,&len); printf("Enter the text\n"); scanf("%s",str); i=0; while(i<strlen(str)) { memset(frame,0,20); strncpy(frame,str+i,SIZE); printf("Transmitting Frames"); len=strlen(frame); for(j=0;j<len;j++) { printf("%d",i+j); sprintf(temp,"%d",i+j); strcat(frame,temp); } printf("\n"); write(lfd,frame,sizeof(frame)); read(lfd,ack,20); sscanf(ack,"%d",&status); if(status==-1) printf("Transmission is successful\n"); else { printf("Received error in %d\n\n",status); printf("\n\nRetansmitting Frame"); for(j=0;;) { frame[j]=str[j+status]; j++; printf("%d",j+status); if((j+status)%4==0) break; } printf("\n"); frame[j]='\0'; len=strlen(frame); for(j=0;j<len;j++) { sprintf(temp,"%d",j+status); strcat(frame,temp);

Page 20: DS file (1)

} write(lfd,frame,sizeof(frame)); } i+=SIZE; } write(lfd,"exit",sizeof("exit")); printf("Exiting\n"); sleep(2); close(lfd); close(sfd); }

CLIENT :

#include<stdio.h> #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> void main() { int sfd,lfd,len,choice; char str[20],str1[20],err[20]; if(sfd<0) perror("FdError"); bzero(&saddr,sizeof(saddr)); saddr.sin_family=AF_INET; inet_pton(AF_INET,"a27.0.0.1",&saddr.sin_addr); saddr.sin_port=htons(4980); connect(sfd,(struct sockaddr*)&saddr,sizeof(saddr)); for(;;) { read(sfd,str,20); if(!strcmp(str,"exit")) { printf("Exiting\n"); break; } printf("\n\nReceived%s\n\n1.do u want to report an error(1-Yes 0- no)",str); scanf("%d",&choice); if(!choice) write(sfd,"-1",sizeof("-1")); else { printf("Enter the sequence no of the frame where error has occurred\n");

Page 21: DS file (1)

scanf("%s",err); write(sfd,err,sizeof(err)); read(sfd,str,20); printf("\n\nReceived the re-transmitted frames%s\n\n",str);}}

Program no. 7

Objective : WAP to implement CORBA mechanism by using C++ program at one end and ‘Java’ on the other.

Theory :

The Common Object Request Broker Architecture (or CORBA) is an industry standard developed by the Object Management Group (OMG) to aid in distributed objects programming. It is a middleware design that allows application programs to communicate with one another irrespective of their programming languags, their hardware and software platforms,the networks they communicate over.

Applications are built from CORBA object, which implement interfaces defined I CORBA’s interface definition language, IDL. Client access the methods in IDL interfacdes of CORBA objects by means of RMI. The middleware component that supports RMI is called Object Request Broker (ORB). ORB allows a client to invoke a method on an object. This role involves locating the object, activating the object if necessary and then communicating the client’s request to the object.

Coding :

Writing the IDL :

interface CaesarAlgorithm { typedef sequence<char> charsequence; charsequence encrypt(in string info,in unsigned long k,in unsigned long shift); string decrypt(in charsequence info,in unsigned long k,in unsigned long shift); boolean shutdown();};

Generating the Skeleton and the Stub :

idl crypt.idl

Page 22: DS file (1)

Implementing the Servant Class :

#include <iostream>#include <string>#include "OB/CORBA.h"#include "crypt_skel.h"

class CryptographicImpl : virtual public ::POA_CaesarAlgorithm, virtual public PortableServer::RefCountServantBase{

CORBA::ORB_var orb;public:

CryptographicImpl(CORBA::ORB_var orb){

this->orb = orb;}virtual ::CaesarAlgorithm::charsequence* encrypt(const char* info,::CORBA::ULong k,::CORBA::ULong shift)throw(::CORBA::SystemException)

{std::string msg = info;int len = msg.length();::CaesarAlgorithm::charsequence* outseq =new

::CaesarAlgorithm::charsequence;outseq->length(len + 1);std::string::iterator i = msg.begin();std::string::iterator end = msg.end();int j = 0;while (i != end){

*i+= shift; *i ^= k; (*outseq)[j++] = *i++;

}(*outseq)[len] = '\0';return outseq;

}virtual char* decrypt(const ::CaesarAlgorithm::charsequence& info,::CORBA::ULong k,::CORBA::ULong shift)throw(::CORBA::SystemException){

char* r = CORBA::string_alloc(info.length()); for (int i = 0;i < info.length() - 1;i++)

{r[i] = info[i];r[i] ^= k;

Page 23: DS file (1)

r[i] -= shift; }

r[info.length() - 1] = '\0';return r;

}virtual ::CORBA::Boolean shutdown()

throw(::CORBA::SystemException){

orb->shutdown(false);return true;

}};

Creating the Server :

#include <iostream>#include "OB/CORBA.h"#include <OB/Cosnaming.h>#include "crypt.h"#include "cryptimpl.h"using namespace std;int main(int argc, char** argv){

CORBA::ORB_var orb;CryptographicImpl* CrypImpl = NULL;

try { orb = CORBA::ORB_init(argc, argv); CORBA::Object_var rootPOAObj =

orb->resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (rootPOAObj.in());

CORBA::PolicyList policies;policies.length(1);policies[0] =rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);PortableServer::POAManager_var manager = rootPOA-

>the_POAManager();PortableServer::POA_var myPOA = rootPOA-

>create_POA("myPOA", manager, policies); CORBA::ULong len = policies.length();

for (CORBA::ULong i = 0; i < len; i++)policies[i]->destroy();

CORBA::Object_var rootContextObj =

Page 24: DS file (1)

orb->resolve_initial_references("NameService");CosNaming::NamingContext_var nc =

CosNaming::NamingContext::_narrow(rootContextObj.in());CrypImpl = new CryptographicImpl(orb);PortableServer::ObjectId_var myObjID =

myPOA->activate_object(CrypImpl);CORBA::Object_var o = myPOA-

>servant_to_reference(CrypImpl);CORBA::String_var s = orb->object_to_string(o);cout << "The IOR of the object is: " << s.in() << endl;CosNaming::Name name;name.length(1);name[0].id = (const char *) "CryptographicService";name[0].kind = (const char *) "";nc->rebind(name,o);manager->activate();cout << "The server is ready. Awaiting for incoming requests..."

<< endl; orb->run();

} catch(const CORBA::Exception& e) {

cerr << e << endl; } if (CrypImpl) CrypImpl->_remove_ref(); if (!CORBA::is_nil(orb)) {

try{ orb->destroy();

cout << "Ending CORBA..." << endl; }

catch (const CORBA::Exception& e) {

cout << "orb->destroy() failed:" << e << endl; return 1;

} } return 0;}

Implementing the Client :

#include <iostream>#include <string>#include "OB/CORBA.h"

Page 25: DS file (1)

#include "OB/Cosnaming.h"#include "crypt.h"using namespace std;int main(int argc, char** argv){

CORBA::ORB_var orb;try {

orb = CORBA::ORB_init(argc, argv);CORBA::Object_var rootContextObj =

orb->resolve_initial_references("NameService");CosNaming::NamingContext_var nc =

CosNaming::NamingContext::_narrow(rootContextObj.in());CosNaming::Name name;name.length(1);name[0].id = (const char *) "CryptographicService";name[0].kind = (const char *) "";CORBA::Object_var managerObj = nc->resolve(name);::CaesarAlgorithm_var manager =

::CaesarAlgorithm::_narrow(managerObj.in());string info_in,exit,dummy;CORBA::String_var info_out;::CaesarAlgorithm::charsequence_var inseq;unsigned long key,shift;try{

do{cout << "\nCryptographic service client" << endl;cout << "----------------------------" << endl;do{

if (cin.fail()){

cin.clear();cin >> dummy;

}cout << "Enter encryption key: ";cin >> key;

} while (cin.fail());do{

if (cin.fail()){

cin.clear();cin >> dummy;

}cout << "Enter a shift: ";cin >> shift;

} while (cin.fail());getline(cin,dummy);

Page 26: DS file (1)

cout << "Enter a plain text to encrypt: ";getline(cin,info_in);inseq = manager->encrypt

(info_in.c_str(),key,shift);cout << "--------------------------------------------“<< endl;cout << "Encrypted text is: " << inseq->get_buffer()

<< endl;info_out = manager->decrypt(inseq.in(),key,shift);cout << "Decrypted text is: " << info_out.in() <<

endl;cout << "-------------------------------------------"<< endl;cout << "Exit? (y/n): ";cin >> exit;

} while (exit!="y");manager->shutdown();

} catch(const std::exception& std_e) {

cerr << std_e.what() << endl; }}

catch(const CORBA::Exception& e) {

cerr << e << endl; }

if (!CORBA::is_nil(orb)) {

try{orb->destroy();cout << "Ending CORBA..." << endl;

} catch(const CORBA::Exception& e)

{cout << "orb->destroy failed:" << e << endl;return 1;

} } return 0;}Running the Client-server Application :

nameserv -OAhost localhost -OAport 8140server -ORBInitRef NameService=corbaloc:iiop:localhost:8140/NameService

Page 27: DS file (1)

client -ORBInitRef NameService=corbaloc:iiop:localhost:8140/NameService