Академический Документы
Профессиональный Документы
Культура Документы
1.UDP ECHO
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss udpechoserver.c
[student@localhost network_lab]$ ./ss 3000
//Client Terminal
[student@localhost network_lab]$ gcc -o cc udpechoclient.c
[student@localhost network_lab]$ ./cc localhost 3000
PROGRAM CODE :
// UDP Chat Server
#include<stdio.h>
#include<string.h> //For bzero()
#include<sys/socket.h> //For socket(), bind()
#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<arpa/inet.h> //For htonl(), htons()
#include<stdlib.h> //For atoi()
#include<unistd.h> //For read(), write(), close()
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss udpchatserver.c
[student@localhost network_lab]$ ./ss 2222
//Client Terminal
[student@localhost network_lab]$ gcc -o cc udpchatclient.c
[student@localhost network_lab]$ ./cc localhost 2222
PROGRAM CODE :
// UDP File Server
#include<stdio.h>
#include<sys/socket.h> //For socket(), bind()
#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<arpa/inet.h> //For htonl(), htons()
#include<stdlib.h> //For atoi()
#include<unistd.h> //For read(), write(), close()
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss udpfileserver.c
[student@localhost network_lab]$ ./ss 2345
//Client Terminal
[student@localhost network_lab]$ gcc -o cc udpfileclient.c
[student@localhost network_lab]$ ./cc localhost 2345
PROGRAM CODE :
OUTPUT :
//Server terminal
[student@localhost network_lab]$ gcc -o ss tcpechoserver.c //Compile command
[student@localhost network_lab]$ ./ss 1234 //Run command
//Server Terminal
[student@localhost network_lab]$ gcc -o ss tcpchatserver.c
[student@localhost network_lab]$ ./ss 1222
//Client Terminal
[student@localhost network_lab]$ gcc -o cc tcpchatclient.c
[student@localhost network_lab]$ ./cc localhost 1222
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss tcpfileserver.c
[student@localhost network_lab]$ ./ss 5000
//Client Terminal
[student@localhost network_lab]$ gcc -o cc tcpfileclient.c
[student@localhost network_lab]$ ./cc localhost 5000
PROGRAM CODE :
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss slidingwindowserver.c
[student@localhost network_lab]$ ./ss 2255
Recieved error in 2
Transmitting frames456
Transmission success
Exiting
//Client Terminal
[student@localhost network_lab]$ gcc -o cc slidingwindowclient.c
[student@localhost network_lab]$ ./a.out localhost 2255
PROGRAM CODE :
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<arpa/inet.h>
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss stopwaitserver.c
[student@localhost network_lab]$ ./ss 6655
FRAME NO DATA
0 A
1 B
2 C
3 D
Received the frame 3 already
4 E
5 F
6 G
7 H
8 I
//Client Terminal
[student@localhost network_lab]$ gcc -o cc stopwaitclient.c
[student@localhost network_lab]$ ./cc localhost 6655
PROGRAM CODE :
//ARP program
#include<sys/types.h>
#include<sys/socket.h>
#include<net/if_arp.h>
#include<sys/ioctl.h>
#include<stdio.h>
#include<string.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<stdlib.h>
PROGRAM CODE :
//DNS Program
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include<arpa/inet.h>
OUTPUT :
PROGRAM CODE :
//Ping program
#include <stdlib.h>
#include <stdio.h>
#include <oping.h>
PROGRAM CODE :
/*simp.x*/
struct operands /*Structure for input arguments*/
{
int x;
int y;
};
program SIMP_PROG
{
version SIMP_VERSION
{
int ADD(operands) = 1; /*Procedure_no_1*/
int SUB(operands) = 2; /*Procedure_no_2*/
} = 1; /*Version_no*/
}=555555555; /*Program_no*/
//rpcserver.c
#include"simp.h" //Autogenerated file by rpcgen
#include"stdio.h"
OUTPUT :
//Server Terminal
[student@localhost network_lab]$ gcc -o ss rpcserver.c simp_svc.c simp_xdr.c
[student@localhost network_lab]$ ./ss
//Client Terminal
[student@localhost network_lab]$ gcc -o cc rpcclient.c simp_clnt.c simp_xdr.c
[student@localhost network_lab]$ ./cc localhost 60 10
60 + 10 = 70
60 - 10 = 50
Filename: rint.java
import java.io.*;
import java.rmi.*;
public interface rint extends Remote
{
public int add(int a,int b)throws RemoteException;
publicintsub(intx,inty)throwsRemoteException;
public int mul(int p,int q)throws RemoteException;
}
File Name: rclass.java
importjava.io.*;
import java.rmi.*;
import java.net.*;
import java.rmi.server.*;
public class rclass extends UnicastRemoteObject implements rint
{
publicrclass()throwsRemoteException{}
publicintadd(inta,intb)throwsRemoteException
{
intc=a+b;
returnc;
}
publicintsub(intx,inty)throwsRemoteException
{
intd=x-y;
returnd;
}
publicintmul(intp,intq)throwsRemoteException
{
inte=p*q;
returne;
}
}
File Name: sclass.java
Importjava.io.*;
import java.rmi.*;
import java.net.*;
public class sclass
{
public static void main(String args[ ])
{
try
{
rclass r=new rclass();
Naming.rebind("sum",r);
}
catch(Exceptione){}
}
}
Filename: cclass.java
import java.io.*;
import java.rmi.*;
public class cclass
{
public static void main(String args[])
{
try
{
int b,b1;
Strings;
s="rmi://localhost/sum";
rintx=(rint)Naming.lookup(s);
b=Integer.parseInt(args[0]);
b1=Integer.parseInt(args[1]);
intz=x.add(b,b1);
intz1=x.sub(b,b1);
int z2=x.mul(b,b1);
System.out.println("Sum"+z);
System.out.println("Difference"+z1);
System.out.println("Product"+z2);
}
catch(Exceptione){ }
}
}
OUTPUT
Sum 4
Difference 0
Production 4
13.SIMULATION OF SNMP
PROGRAM CODE :
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
int main()
{
int csd,cport,len,i;
char sendmsg[20],rcvmsg[100],rmsg[100],oid[100];
struct sockaddr_in servaddr;
printf("\nEnter the port\t:\t");
scanf("%d",&cport);
csd=socket(AF_INET,SOCK_STREAM,0);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(cport);
printf("\nSocket created successfully");
if(connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("\nError in connection");
else
printf("\nAgent connected");
printf("\n1.Client window size");
printf("\n2.System date and time");
printf("\nEnter the number for the type of information needed\t:\t");
scanf("%d",&i);
if(i==1)
{
printf("\nEnter the object ID for client\t:\t");
scanf("%s",oid);
send(csd,oid,100,0);
recv(csd,rcvmsg,100,0);
printf("\nThe window size of %s is %s",oid,rcvmsg);
}
else
{
printf("\nEnter the object ID for system\t:\t");
scanf("%s",oid);
send(csd,oid,100,0);
recv(csd,rmsg,100,0);
printf("\nThe manufacturing date for %s is %s",oid,rmsg);
recv(csd,rmsg,100,0);
printf("\nThe time of last utilization for %s is %s",oid,rmsg);
}}
//SNMP Agent 1 (Server code)
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
int main()
{
int i,j,sd,sd2,nsd,clilen,sport,len;
char sendmsg[20],recvmsg[100];
char oid[5][10]={"client1","client2","client3","client4","client5"};
char wsize[5][5]={"5","10","15","3","6"};
struct sockaddr_in servaddr,cliaddr;
printf("\nEnter the server port\t:\t");
scanf("%d",&sport);
sd=socket(AF_INET,SOCK_STREAM,0);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(sport);
printf("\nSocket created successfully");
sd2=bind(sd,(struct sockaddr*)&servaddr,sizeof(servaddr));
if(sd2<0)
printf("\nError in bind");
else
printf("\nBinded successfully");
listen(sd,5);
clilen=sizeof(cliaddr);
nsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen);
if(nsd<0)
printf("\nError on accept");
else
printf("\nAccepted");
recv(nsd,recvmsg,100,0);
for(i=0;i<5;i++)
if(strcmp(recvmsg,oid[i])==0)
send(nsd,wsize[i],100,0);
else
continue;
}
//SNMP Agent 2 (Server code)
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
int main()
{
int i,j,sd,sd2,nsd,clilen,sport,len;
char sendmsg[20],recvmsg[100];
char oid[5][10]={"system1","system2","system3","system4","system5"};
char mdate[5][15]={"1.10.95","10.03.08","14.03.81","11.07.07","17.12.77"};
char time[5][15]={"9am","10pm","11am","12.30pm","11.30am"};
struct sockaddr_in servaddr,cliaddr;
printf("\nEnter the server port\t:\t");
scanf("%d",&sport);
sd=socket(AF_INET,SOCK_STREAM,0);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(sport);
printf("\nSocket created successfully");
sd2=bind(sd,(struct sockaddr*)&servaddr,sizeof(servaddr));
if(sd2<0)
printf("\nError in bind");
else
printf("\nBinded successfully");
listen(sd,5);
clilen=sizeof(cliaddr);
nsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen);
if(nsd<0)
printf("\nError on accept");
else
printf("\nAccepted");
recv(nsd,recvmsg,100,0);
for(i=0;i<5;i++)
{
if(strcmp(recvmsg,oid[i])==0)
{
send(nsd,mdate[i],100,0);
send(nsd,time[i],100,0);
}
else
continue;
}
}
OUTPUT :