Professional Documents
Culture Documents
DS File
DS File
LABORATORY MANUAL
Name
Roll No.
Section-Batch
Create an inspiring ambience that raises the motivation level for conducting quality research.
To empower professionals with core competency in the field of Computer Science and Engineering.
To foster independent and life long learning with ethical and social responsibilities.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.
Program 1:
Objective: WAP TO IMPLEMENT LAMPORT LOGICAL CLOCK
CODE:
#include<stdio.h>
#include<conio.h>
int maxx(int,int,int);
void main(){
int i, p1[4], p2[3], p3[4];
int d=1;
p1[1]=1;
p2[1]=1;
p3[1]=1;
for(i=1;i<=4;i++)
if(i>1)
p1[i]=p1[i-1]+d;
for(i=1;i<=4;i++)
if(i>1)
p3[i]=p3[i-1]+d;
for(i=1;i<=3;i++) {
if(i==2)
p2[i]=maxx(p1[2],p2[1],p3[1])+d;
else if(i==3)
p2[i]=maxx(p1[3],p2[2],p3[4])+d;
}
printf("\nClock values are:\nP1:");
for(i=1;i<=4;i++)
printf("\t%d",p1[i]);
printf("\nP2:");
for(i=1;i<=3;i++)
printf("\t%d",p2[i]);
printf("\nP3:");
for(i=1;i<=4;i++)
printf("\t%d",p3[i]);
getch();}
int maxx(int p,int q,int r)
{
if(p>q)
{
if(p>r)
return(p);
else
return(r); }
else
{
if(q>r)
return(q);
else
return(r);
}}
OUTPUT:
Program 2:
Objective:WAP TO IMPLEMENT LAMPORT NON TOKEN
BASEDMUTUAL EXCLUSION ALGORITHM
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int s[10],n,i,ch=1,temp,j;
printf("\n enter the number of sites");
scanf("\n %d",&n);
for (i=0;i<n;i++)
{
printf("\n enter the timestamp of %d process",i+1);
scanf("%d",&s[i]);
}
for(i=0;i<n;i++)
for(j=n-1;j>=i+1;j--)
if(s[j]<s[j-1])
{
temp=s[j];
s[j]=s[j-1];
s[j-1]=temp;
}
for(i=0;i<n;i++)
printf("\n %d",s[i]);
while(ch!=0)
{
printf("\n enter the choice");
printf("\n 1.reqesting a critical section");
printf("\n 2. releasing a critical section");
printf("\n 0.exit");
scanf("\n %d",&ch);
switch(ch)
{
case 1 :
printf("\n enter the timestamp");
scanf("\n %d",&s[n]);
n++;
for(i=0;i<n;i++)
for(j=n;j>=i+1;j--)
if(s[j]>s[j+1])
{
temp=s[j];
s[i]=s[j+1];
s[j+1]=temp;
}
for(i=0;i<n;i++)
printf("\n %d",s[i]);
break;
case 2:
s[n]=0;
n--;
}
}
getch();
}
OUTPUT:
Program 3:
Objective:PROGRAM USING TCP SOCKET: CLIENT-SERVER IN C
CODE:
SERVER:
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<errno.h>
#include<unistd.h>
sid=socket(AF_INET,SOCK_DGRAM,0);
if(sid<0)
perror("socket_create");
bzero((char*)&saddr,sizeof(saddr));
saddr.sin_family=AF_INET;
saddr.sin_port=htons(atoi(argv[1]));
saddr.sin_addr.s_addr=INADDR_ANY;
clen=sizeof(caddr);
bzero(buffer,1024);
n=recvfrom(sid,buffer,1023,0,(struct sockaddr*)&caddr,&clen);
if(n<0)
perror("receive");
CLIENT:
#include <netdb.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
if(argc<3)
{
fprintf(stderr,”Error: Host name and port is not given \n”);
exit(1);
}
sid=socket(AF_INET,SOCK_DGRAM,0);
if(sid<0)
perror("Socket create");
hen=gethostbyname(argv[1]);
if(hen==NULL)
{
fprintf(stdout,"Host not found");
exit(1);
}
saddr.sin_family=AF_INET;
saddr.sin_port=htons(atoi(argv[2]));
bcopy((char *)hen->h_addr,(char *)&saddr.sin_addr.s_addr,hen->h_length);
if(bind(sid,(struct sockaddr *)&saddr,sizeof(saddr))<0)
perror("Socket_bind");
OUTPUT:
CLIENT:
[root@localhost]$ cc udpclient.c
[root@localhost]$ cc udpclient.c -o
ucli[root@localhost]$ ./ucli localhost 3927
Enter the data u want to send :Hello, how are you?
[root@localhost]$
SERVER:
[root@localhost]$ cc udpserver.c
[root@localhost]$ cc udpserver.c -o user
[root@localhost]$ ./user 3927The msg is Hello, how are you?
[root@localhost]$
Program 4:
Objective:IMPLEMENT JAVA RMI MECHANISM FOR
ACCESSINGMETHODS OF REMOTE SYSTEMS.
CODE:
1. CalculatorImpl.java
2. Calculator.java
throws java.rmi.RemoteException;
public long sub(long a, long b)
throws java.rmi.RemoteException;
public long mul(long a, long b)
throws java.rmi.RemoteException;
public long div(long a, long b)
throws java.rmi.RemoteException;
}
3. CalculatorServer.java
import java.rmi.Naming;
public class CalculatorServer {
public CalculatorServer() {
try {
Calculator c = new CalculatorImpl();
Naming.rebind("rmi://localhost:1099/CalculatorService", c);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
public static void main(String args[]) {
new CalculatorServer();
}
}
4. CalculatorClient.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
public class CalculatorClient {
public static void main(String[] args) {
try {
Calculator c = (Calculator)
Naming.lookup("rmi://localhost/CalculatorService");
System.out.println( c.sub(4, 3) );
System.out.println( c.add(4, 5) );
System.out.println( c.mul(3, 6) );
System.out.println( c.div(9, 3) );
}
D:\Nipun\RND\Java\NetWorking\RMI>rmic CalculatorImpl
Now open three cmd prompts and follow these at each.
1. D:\Nipun\RND\Java\NetWorking\RMI>Rmiregistry
2. D:\Nipun\RND\Java\NetWorking\RMI>java CalculatorServer
3. D:\Nipun\RND\Java\NetWorking\RMI>java CalculatorClient
OUTPUT:
1
9
18
3
Program 5:
Objective:IMPLEMENTATION OF CORBA (COMMONOBJECT
REQUEST BROKER ARCHITECTURE) MECHANISM.
CODE:
1. FileInterface.idl
interface FileInterface {
typedef sequence<octet> Data;
Data downloadFile(in string fileName);
};
NOTE:Now, let's compile the FileInterface.idl and generate server-side skeletons. Using
thecommand:
2. FileServant.java
import java.io.*;
3. FileServer.java
import java.io.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
4. FileClient.java
import java.io.*;
import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
if(argv.length < 1) {
System.out.println("Usage: java FileClient filename");
}
output.close();
} catch(Exception e) {
System.out.println("FileClient Error: " + e.getMessage());
e.printStackTrace();
}
}
}
1.D:\Nipun\RND\Java\CORBA>tnameserv
2.D:\Nipun\RND\Java\CORBA>java FileServer
3.D:\Nipun\RND\Java\CORBA>idlj -fclient FileInterface.idl
4.D:\Nipun\RND\Java\CORBA>java FileClient hello.txt
OUTPUT:
Program 6:
Objective: SLIDING WINDOW PROTOCOL PROGRAM IN C
CODE:
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0;
}
OUTPUT:
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the
receiver 12 5 89
sender 4 6
Program 7:
Objective: IMPLEMENT RPC MECHANISM FOR A FILE
TRANSFERACROSS A NETWORK IN C
CODE:
SERVER: server.c
#include"rpc/rpc.h"
#include"square.h"
#include"stdio.h"
#include"stdlib.h"
#include"math.h"
CLIENT: client.c
#include"errno.h"
#include"rpc/rpc.h"
#include"square.h"
#include"stdio.h"
#include"stdlib.h"
#include"math.h"
intmain(intargc,char**argv)
{
CLIENT *cl;
square_in in;
square_out *outp;
f(argc!=3)
{
printf("\n\n error:insufficient arguments!!!");
exit(-1);
}
cl=clnt_create(argv[1],SQUARE_PROG,SQUARE_VERS,"tcp");
in.arg1=atol(argv[2]);
if(cl==NULL)
{
printf("\nerror:%s",strerror(errno));
exit(-1);
}
if((outp=squareproc_1(&in,cl))==NULL)
{
printf("\nerror :%s",clnt_sperror(cl,argv[1]));
exit(-1);
}
structsquare_in
{
/*input arg*/
longarg1;
};
structsquare_out
{
/*op result*/
longres1;
};
program SQUARE_PROG
{
version SQUARE_VERS
{
square_out SQUAREPROC(square_in)=1; /*proc no=1*/
}=1; /*version no*/
}=0x31230000;/*prog no*/
OUTPUT:
[root@localhost~]#rpcgen -C square.x
[root@localhost~]#cc -c client.c -o client.o
[root@localhost~]#cc -c square_clnt.c -o square_clnt.o
[root@localhost~]#cc -c square_xdr.c -o square.xdr.o
[root@localhost~]#cc -o client client.o square_clnt.o square_xdr.o
[root@localhost~]#cc -c client.c server.c square_xdr.c
[root@localhost~]#cc -c server.c -o server.o
[root@localhost~]#cc -c square_svc.c -o square_svc.o
[root@localhost~]#cc -o server server.o square_svc.o square_xdr.o
[root@localhost~]#./server &
[1] 2264
[root@localhost~]#./client localhost 4
result is: 16