0% found this document useful (0 votes)
383 views46 pages

Network Programming Lab Manual PDF

The document provides instructions for 11 exercises on network programming lab. Exercise 2 details a C program to implement communication between two endpoints using TCP sockets. The server program creates a socket, binds it to a port, listens for connections and receives/sends messages. The client program creates a socket, connects to the server and sends/receives messages until receiving "bye". Exercise 3 similarly implements communication between endpoints using UDP sockets, with the server receiving messages and client sending messages via datagrams.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
383 views46 pages

Network Programming Lab Manual PDF

The document provides instructions for 11 exercises on network programming lab. Exercise 2 details a C program to implement communication between two endpoints using TCP sockets. The server program creates a socket, binds it to a port, listens for connections and receives/sends messages. The client program creates a socket, connects to the server and sends/receives messages until receiving "bye". Exercise 3 similarly implements communication between endpoints using UDP sockets, with the server receiving messages and client sending messages via datagrams.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 46

B.

Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

Subject Name: Network Programming Lab


Subject code: BCS18L05
Programme Name: B. Tech, IT
Regulation: 2018

STAFF MANUAL

1
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

Exercises

Table of Contents

Ex.No. Name of the Exercises Page no.

1 Networking Commands with Options 3

Socket program to extent communication between two deferent ends


2 5
using TCP

Socket program to extent communication between two deferent ends


3 9
using UDP

Create a Socket (TCP) between two computers and enable file


4 12
transfer between them.

5 Implementation of RPC in server-client model 16

6 Implementation of ARP/RARP 19

7 HTTP Socket program to download a web page 23

File transfer in Client-Server architecture using following methods


8 26
a) Using RS232C b) Using TCP/IP

9 To implement RMI (Remote Method Invocation) 33

Write a network program to broadcast/ multicast a message to a


10 35
group in the same network.

11 Demonstration of Network Simulators 44

2
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 1 NETWORKING COMMANDS WITH OPTIONS

AIM:
To work on networking commands with options in Windows Operating System.

ALGORITHM:
1. Start the program.
2. Open the command prompt
3. Enter the commands along with proper options
4. View the Command Output

CODING:

IPCONFIG
ipconfig [/allcompartments] [/? | /all | /renew [adapter] | /release [adapter] | /renew6 [adapter] |
/release6 [adapter] | /flushdns | /displaydns | /registerdns | /showclassid adapter | /setclassid
adapter [classid] | /showclassid6 adapter | /setclassid6 adapter [classid] ]

TRACERT
tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name

PING
ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] [-r count] [-s count] [[-j host-list] | [-k
host-list]] [-w timeout] [-R] [-S srcaddr] [-4] [-6 target_name

ROUTE
ROUTE [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC metric]
[IF interface]

NBTSTAT
NBTSTAT [ [-a RemoteName] [-A IP address] [-c] [-n] [-r] [-R] [-RR] [-s] [-S] [interval] ]

3
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

OUTPUT:

RESULT:
Thus the Network Commands with options for Windows Operating System has been
executed successfully.

4
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 2 SOCKET PROGRAM TO EXTENT COMMUNICATION


BETWEEN TWO DEFERENT ENDS USING TCP
AIM:
To write a C program for implementing Socket program to extent communication
between two deferent ends using TCP.

ALGORITHM:

SERVER
Step 1: Start the program.
Step 2: Create an unnamed socket for the server using the
parameters AF_INET as domain and the SOCK_STREAM as type.
Step 3: Name the socket using bind( ) system call with the
parameters server_sockfd and the server address(sin_addr and sin_sport).
Step 4: Create a connection queue and wait for clients using the listen( ) system call
with the number of clients request as parameters.
Step 5: Accept the connection using accept( ) system call when client requests for
connection.
Step 6: Get the message which has to be sent to the client and check that it is not
equal to ‘Bye’.
Step 7: If the message is not equal to ‘Bye’ then write the message to the client and
Goto step 6.
Step 8: If the message is ‘Bye’ then terminate the Process.
Step 9: Stop the program execution.

CLIENT
Step 1: Start the program.
Step 2: Create an unnamed socket for client using socket( ) system.
Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type.
Step 4: Name the socket using bind( ) system call.
Step 5: Now connect the socket to server using connect( ) system call.
Step 6: Read the message from the server socket and compare it with ‘Bye’.
Step 7: If the message is not equal to ‘Bye’ then print the message to the server
output device and repeat the steps 6 & 7.
Step 8: Get the message from the client side.
Step 9: Write the message to server sockfd and goto step 4.
Step 10:If the message is equal to ‘Bye’then print good bye message and terminate
the process.
Step 11:Stop the process.

CODING

SERVER
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>

5
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

#include<string.h>
main()
{
int sd,sd2,nsd,clilen,sport,len;
char sendmsg[20],rcvmsg[20];
struct sockaddr_in servaddr,cliaddr;
printf("Enter the Server port");
printf("\n_____________________\n");
scanf("%d",&sport);
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd<0)
printf("Can't Create \n");
else
printf("Socket is Created\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(sport);
sd2=bind(sd,(struct sockaddr*)&servaddr,sizeof(servaddr));
if(sd2<0)
printf(" Can't Bind\n");
else
printf("\n Binded\n");
listen(sd,5);
clilen=sizeof(cliaddr);
nsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen);
if(nsd<0)
printf("Can't Accept\n");
else
printf("Accepted\n");
printf("\nReceived Messages\n");
do
{
recv(nsd,rcvmsg,20,0);
printf("%s",rcvmsg);
fgets(sendmsg,20,stdin);
len=strlen(sendmsg);
sendmsg[len-1]='\0';

6
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

send(nsd,sendmsg,20,0);
wait(20);
}
while(strcmp(sendmsg,"bye")!=0);
}
CLIENT
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
main()
{
int csd,cport,len;
char sendmsg[20],revmsg[20];
struct sockaddr_in servaddr;
printf("Enter the port\n");
scanf("%d",&cport);
csd=socket(AF_INET,SOCK_STREAM,0);
if(csd<0)
printf("Can't Create\n");
else
printf("Scocket is Created\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(cport);
if(connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("Can't Connect\n");
else
printf("Connected\n");
do
{
fgets(sendmsg,20,stdin);
len=strlen(sendmsg);
sendmsg[len-1]='\0';
send(csd,sendmsg,20,0);
wait(20);
recv(csd,revmsg,20,0);
printf("%s",revmsg);
}
while(strcmp(revmsg,"bye")!=0);
}

7
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

OUTPUT:
Client Side
[1me16@localhost ~]$ cc tcpclient.c
[1me16@localhost ~]$. /a.out
Enter the port
6523
Socket is Created…
Connected……
Hello
Server Side
[1me16@localhost ~]$ cc tcpserver.c.c
[1me16@localhost ~]$. /a.out
Enter the server port…
6543
Socket is Created
Binded
Accepted
Received Messages…. Hello

RESULT:
Thus the C program for implementing Socket program to extent communication between
two deferent ends using TCP is executed and the output is verified successfully.

8
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 3 SOCKET PROGRAM TO EXTENT COMMUNICATION BETWEEN


TWO DEFERENT ENDS USING UDP

AIM:
To write a C program for implementing Socket program to extent communication
between two deferent ends using UDP.

ALGORITHM :

SERVER
Step 1: Start the program.
Step 2: Create an unnamed socket for the server using the
parameters AF_INET as domain and the SOCK_DGRAM as type.
Step 3: Name the socket using bind( ) system call with theparameters server_sockfd
and the server address(sin_addr and sin_sport).
Step 4: The server gets the message from the client.
Step 5: Prints the message.
Step 6: Stop the program execution.

CLIENT
Step 1: Start the program.
Step 2: Create an unnamed socket for client using socket
Step 3: Call with parameters AF_INET as domain an SOCK_DGRAM as type.
Step 4: Name the socket using bind( ) system call.
Step 5: The Sendto( ) system call is used to deliver the Message to the server.
Step 6: Stop the program execution.

CODING:

SERVER
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
main()
{
struct sockaddr_in sadd,cadd;
int id,a,b,len,port;
char rbuff[100];
id=socket(PF_INET,SOCK_DGRAM,0);
if(id<0)
printf("Can't Create\n");
else
printf("Created\n");
printf("Enter the port Address\n");
printf("____________________\n");
scanf("%d",&port);

9
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

sadd.sin_family=PF_INET;
sadd.sin_addr.s_addr=htonl(INADDR_ANY);
sadd.sin_port=htons(port);
b=bind(id,(struct sockaddr*)&sadd,sizeof(sadd));
if(b<0)
printf("Can't Bind");
else
printf("Binded\n");
printf("~~~~~~\n");
len=sizeof(cadd);
if(recvfrom(id,rbuff,sizeof(rbuff),0,(struct sockaddr*)&cadd,&len)<0)
printf("Received Error\n");
else
printf("Server received =%s\n",rbuff);
close(id);
}

CLIENT
#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
main()
{
struct sockaddr_in sadd,cadd;
int id,len,n,c,s,b,port;
char str[100],serstr[100];
id=socket(PF_INET,SOCK_DGRAM,0);
if(id<0)
printf("Can't Create\n");
else
printf("Socket is Created\n");
printf("Enter the IP address\n");
scanf("%s",serstr);
printf("Enter the port Address\n");
scanf("%d",&port);
cadd.sin_family=PF_INET;
cadd.sin_addr.s_addr=inet_addr(serstr);
cadd.sin_port=htons(port);
printf("Enter the Data\n");
scanf("%s",str);
b=bind(id,(struct sockaddr*)&cadd,sizeof(cadd));
if(sendto(id,str,sizeof(str),0,(struct sockaddr*)&cadd,sizeof(cadd))<0)
printf("Transmit Error");
else
printf("Server Transmitted=%s\n",str);

10
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

close(id);
}

OUTPUT:
Client Side
[1me16@localhost ~]$ cc udpclient.c
[1me16@localhost ~]$. /a.out
Socket is Created…
Enter the IP Address
172.15.170.104
Enter the port address
6543
Enter the data
Hello
Server transmitted = hello
Server Side
[1me16@localhost ~]$ cc udpserver.c
[1me16@localhost ~]$. /a.out
Created
Enter the port address
………….
6543
Binded
…………….

RESULT:
Thus the C program for implementing Socket program to extent communication between
two deferent endsusing UDP is executed and the output is verified successfully.

11
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 4 CREATE A SOCKET (TCP) BETWEEN TWO COMPUTERS AND


ENABLE FILE TRANSFER BETWEEN THEM

AIM:
To write a C program for transferring a file between two computers using TCP.

ALGORITHM:

SERVER:
Step 1:Start the program.
Step 2:Create an unnamed socket for the server using parameters AF_INET as
domain and SOCK_STREAM as type.
Step 3:Get the server port number.
Step 4:Register the host address to the system by using bind() system call in server
side.
Step 5:Create a connection queue and wait for clients using listen() system call with
the number of clients requests as parameter.
Step 6:Create a Child process using fork( ) system call.
Step 7:If the process identification number is equal to zero accept the connection
using accept( ) system call when the client request for connection.
Step 8:If pid is not equal to zero then exit the process.
Step 9:Stop the Program execution.
CLIENT:
Step 1:Start the program.
Step 2:Create an unnamed socket for the client using parameters AF_INET as
domain and SOCK_STREAM as type.
Step 3:Get the client port number.
Step 4:Now connect the socket to server using connect( ) system call.
Step 5:Enter the file name.
Step 6:The file is transferred from client to server using send ( ) function.
Step 7:Print the contents of the file in a new file.
Step 8:Stop the program.

CODING:

SERVER
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
main()
{
FILE *fp;
int sd,newsd,ser,n,a,cli,pid,bd,port,clilen;
char name[100],fileread[100],fname[100],ch,file[100],rcv[100];
struct sockaddr_in servaddr,cliaddr;
printf("Enter the port address: ");

12
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

scanf("%d",&port);
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd<0)
printf("Can't Create \n");
else
printf("Socket is Created\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(port);
a=sizeof(servaddr);
bd=bind(sd,(struct sockaddr*)&servaddr,a);
if(bd<0)
printf(" Can't Bind\n");
else
printf("\n Binded\n");
listen(sd,5);
clilen=sizeof(cliaddr);
newsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen);
if(newsd<0)
printf("Can't Accept\n");
else
printf("Accepted\n");
n=recv(newsd,rcv,100,0);
rcv[n]='\0';
fp=fopen(rcv,"r");
if(fp==NULL)
{
send(newsd,"error",5,0);
close(newsd);
}
else
{
while(fgets(fileread,sizeof(fileread),fp))
{
if(send(newsd,fileread,sizeof(fileread),0)<0)
{
printf("Can't send\n");
}
sleep(1);
}
if(!fgets(fileread,sizeof(fileread),fp))
{
send(newsd,"completed",999999999,0);
}
return(0);
}

13
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

}
CLIENT
#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
main()
{
FILE *fp;
int csd,n,ser,s,cli,cport,newsd;
char name[100],rcvmsg[100],rcvg[100],fname[100];
struct sockaddr_in servaddr;
printf("Enter the port");
scanf("%d",&cport);
csd=socket(AF_INET,SOCK_STREAM,0);
if(csd<0)
{
printf("Error...");
exit(0);
}
else
printf("Socket is Created...\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);servaddr.sin_port=htons(cport);
if(connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("Error in Connection...\n");
else
printf("Connected...\n");
printf("Enter the existing file name: ");
scanf("%s",name);
printf("\nEnter the new filename: ");
scanf("%s",fname);
fp=fopen(fname,"w");
send(csd,name,sizeof(name),0);
while(1)
{
s=recv(csd,rcvg,100,0);
rcvg[s]='\0';
if(strcmp(rcvg,"error")==0)
printf("File is not Available...\n");
if(strcmp(rcvg,"completed")==0) {
printf("file is transferred...\n");
fclose(fp);
close(csd);
break;
}
else

14
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

fputs(rcvg,stdout);
fprintf(fp,"%s",rcvg);
}
}

OUTPUT:

Server Side
[1me16@localhost ~]$ cc ftpclient.c
[1me16@localhost ~]$. /a.out
Enter the port address:
8663
Socket is Created
Binded
Connected…
Client Side
[1me16@localhost ~]$ cc ftpserver.c
[1me16@localhost ~]$. /a.out
Socket is Created..
Connected
Enter the existing file name: net
Enter the new file name: network
Welcome to Network Lab
File is transferred...

RESULT:
Thus the C program for transferring file from one machine to another machine using TCP
is executed and the output is verified successfully.

15
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 5 IMPLEMENTATION OF RPC IN SERVER-CLIENT MODEL

AIM:
To implement Remote Procedure Call (RPC) in Server-Client Model using Java.

ALGORITHM:

SERVER
Step 1: Start the program.
Step 2: Create an unnamed socket for the server.
Step 3: Name the socket using bind( ) system call with theparameters server_sockfd
and the server address(sin_addr and sin_sport).
Step 4: The server gets the method name from the client.
Step 5: Prints the output of the method.
Step 6: Stop the program execution.

CLIENT
Step 1: Start the program.
Step 2: Create an unnamed socket for client using socket
Step 3: Input the method name to be called from the server.
Step 4: Pass the data to the server.
Step 5: Stop the program execution.

CODING:

CLI.JAVA
import java.io.*;
import java.net.*;
class cli
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Client ready, type and press Enter key");
String receiveMessage, sendMessage,temp;
while(true)
{
System.out.println("\nEnter operation to perform(add,sub,mul,div)....");
temp = keyRead.readLine();
sendMessage=temp.toLowerCase();
pwrite.println(sendMessage);

16
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

System.out.println("Enter first parameter :");


sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.println("Enter second parameter : ");
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.flush();
if((receiveMessage = receiveRead.readLine()) != null)
System.out.println(receiveMessage);
}
}
}
SER.JAVA
import java.io.*;
import java.net.*;
class ser
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready");
Socket sock = sersock.accept( );
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage,fun;
int a,b,c;
while(true)
{
fun = receiveRead.readLine();
if(fun != null)
System.out.println("Operation : "+fun);
a = Integer.parseInt(receiveRead.readLine());
System.out.println("Parameter 1 : "+a);
b = Integer.parseInt(receiveRead.readLine());
if(fun.compareTo("add")==0)
{
c=a+b;
System.out.println("Addition = "+c);
pwrite.println("Addition = "+c);
}
if(fun.compareTo("sub")==0)
{
c=a-b;

17
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

System.out.println("Substraction = "+c);
pwrite.println("Substraction = "+c);
}
if(fun.compareTo("mul")==0)
{
c=a*b;
System.out.println("Multiplication = "+c);
pwrite.println("Multiplication = "+c);
}
if(fun.compareTo("div")==0)
{
c=a/b;
System.out.println("Division = "+c);
pwrite.println("Division = "+c);
}
System.out.flush();
}
}
}

OUTPUT:

E:\java>java ser
Server ready
Operation : add
Parameter 1 : 3
Parameter 2 : 5
Addition = 8
Operation : mul
Parameter 1 : 3
Parameter 2 : 5
Multiplication = 15

E:\java>java cli
Client ready, type and press Enter key

Enter operation to perform(add,sub,mul,div)....


add
Enter first parameter :
3
Enter second parameter :
5
Addition = 8

Enter operation to perform(add,sub,mul,div)....

18
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

mul
Enter first parameter :
3
Enter second parameter :
5
Multiplication = 15

Enter operation to perform(add,sub,mul,div)....

RESULT:
Thus the Java program for implementing Remote Procedure Call is executed and the
output is verified successfully.

EX. NO. 6 IMPLEMENTATION OF ARP/RARP

a)ARP

AIM:
To write a java program for simulating ARP protocols using TCP

ALGORITHM:

Client
1.Start the program
2. Using socket, connection is established between client and server.
3.Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.
Server
1.Start the program
2. Accept the socket which is created by the client.
3.Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.

CODING:

// ARPServer.java - Server
import java.io.*;
import java.net.*;
import java.util.*;

public class ARPServer{

19
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

public static void main(String args[]) {


try{
DatagramSocket server = new DatagramSocket(1309);
while(true){
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1204];
DatagramPacket receiver = new DatagramPacket(receiveByte,receiveByte.length);
server.receive(receiver);
String str = new String(receiver.getData());
String s = str.trim();
InetAddress addr = receiver.getAddress();
int port = receiver.getPort();
String ip[] = {"10.0.3.186"};
String mac[] = {"D4:3D:7E:12:A3:D9"};
for (int i = 0; i < ip.length; i++) {
if(s.equals(ip[i]))
{
sendByte = mac[i].getBytes();
DatagramPacket sender =new datagramPacket(sendByte,sendByte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
}
}

// ARP.java - Client
import java.io.*;
import java.net.*;
import java.util.*;
public class ARP {
public static void main(String args[]){
try{
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1024];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical Address ");

20
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

String str = in.readLine();


sendByte = str.getBytes();
DatagramPacket sender = new DatagramPacket(sendByte,sendByte.length,addr,1309);
client.send(sender);
DatagramPacket receiver = new DatagramPacket(receiveByte,receiveByte.length);
client.receive(receiver);
String s = new String(receiver.getData());
System.out.println("The Logical Address is :" + s.trim());
client.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

OUTPUT:

Enter the Logical Address: 10.0.3.186


The Physical Address is D4:3D:7E:12:A3:D9

b)RARP

AIM:
To write a java program for simulating RARP protocols using TCP.

ALGORITHM:

Client
1. Start the program
2. Using socket connection is established between client and server.
3. Get the MAC address to be converted into IP address.
4. Send this MAC address to server.
5. Server returns the IP address to client.
Server
1. Start the program
2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the MAC address which is send by the client.
5. Map the MAC address with its IP address and return the IP address to client.

CODING:

// RARPServer.java - Server
import java.io.*;
import java.net.*;

21
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

import java.util.*;
public class RARPServer{
public static void main(String args[]) {
try{
DatagramSocket server = new DatagramSocket(1309);
while(true){
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1204];
DatagramPacket receiver = new DatagramPacket(receiveByte,receiveByte.length);
server.receive(receiver);
String str = new String(receiver.getData());
String s = str.trim();
InetAddress addr = receiver.getAddress();
int port = receiver.getPort();
String ip[] = {"10.0.3.186"};
String mac[] = {"D4:3D:7E:12:A3:D9"};
for (int i = 0; i < ip.length; i++) {
if(s.equals(mac[i]))
{
sendByte = ip[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendByte,sendByte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
}
}

// RARP.java - Client
import java.io.*;
import java.net.*;
import java.util.*;
public class RARP {
public static void main(String args[]){
try{
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1024];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

22
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

System.out.println("Enter the Physical Address ");


String str = in.readLine();
sendByte = str.getBytes();
DatagramPacket sender = new DatagramPacket(sendByte,sendByte.length,addr,1309);
client.send(sender);
DatagramPacket receiver = new DatagramPacket(receiveByte,receiveByte.length);
client.receive(receiver);
String s = new String(receiver.getData());
System.out.println("The Logical Address is :" + s.trim());
client.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

OUTPUT:

Enter the Physical Address: D4:3D:7E:12:A3:D9

The Logical Address is 10.0.3.186

RESULT:
Thus the Java program for implementing ARP/RARP is executed and the output is
verified successfully.

23
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 7 HTTP SOCKET PROGRAM TO DOWNLOAD A WEB PAGE

AIM:
To write a HTTP socket program to download a web page.

ALGORITHM:
Step 1: Start the program
Step 2: Create a SocketHTTPClient.java file and add the main method
Step 3: Input the hostname and provide the default port number as 80
Step 4: Create a Socket by passing hostname and port number as parameters.
Step 4: Use the PrintWriter class to retrieve the HTML content
Step 5: Display the content in the console.

CODING:

import java.io.*;
import java.net.*;
import java.util.Scanner;

public class SocketHTTPClient {


public static void main(String[] args) {

Scanner s = new Scanner(System.in);


String hostName = s.next(); //"www.martinbroadhurst.com";
int portNumber = 80;
s.close();
try {
Socket socket = new Socket(hostName, portNumber);
PrintWriter out =
new PrintWriter(socket.getOutputStream(), true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
out.println("GET / HTTP/1.1\nHost: www.martinbroadhurst.com\n\n");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " +
hostName);
System.exit(1);
}

24
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

}
}
OUTPUT:

RESULT:
Thus the Java program for downloading a web page using HTTP Socket is executed and
the output is verified successfully.

25
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 8a FILE TRANSFER BETWEEN CLIENT AND SERVER USING RS232C

AIM:
To write a C program to transfer a file in client-server architecture using RS232C.

ALGORITHM:

SERVER
Step 1: Pass the port number as argument to main function
Step 2: Open the “recvfile.txt” in write mode
Step 3: Create a socket for transferring file using socket()
Step 4: Fill the memory with some constant byte using memset()
Step 5: Define Port family
Step 6: Bind the server to the socket created
Step 7: Listen to signals from client and accept client message
Step 8: Close the socket.
CLIENT
Step 1: Pass the IP address, input file, port number as argument to main function
Step 2: Convert Port number to integer value
Step 3: Open the file in read mode
Step 4: Create a Socket using socket()
Step 5: Fill the memory with constant byte using memset()
Step 6: Define the port family and connect the client to the socket
Step 7: Get the contents from input file and sent it to server over the socket using send()
Step 8: Close the socket.

CODING:

RSSERVER.C
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#define BUF 256
#define MAX 5
int main(int argc,char **argv)
{
int servsock,cIntsock;
struct sockaddr_in echoServAddr,echoIntaddr;
char echoBuffer[BUF];
unsigned int cIntlen,recvMsgsize;
int portno;
FILE *fp=fopen("refile.txt","w");

26
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

portno=atoi(argv[1]);
servsock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
memset(&echoServAddr,0,sizeof(&echoServAddr));
echoServAddr.sin_family=AF_INET;
echoServAddr.sin_addr.s_addr=htonl(INADDR_ANY);
echoServAddr.sin_port=htons(portno);
bind(servsock,(struct sockaddr*) &echoServAddr,sizeof(echoServAddr));
printf("server waiting for the client %d",portno);
listen(servsock,MAX);
cIntlen=sizeof(echoIntaddr);
cIntsock=accept(servsock,(struct sockaddr*)&echoIntaddr,&cIntlen);
recvMsgsize=1;
while(recvMsgsize>0)
{
recvMsgsize=recv(cIntsock,echoBuffer,BUF,0);
echoBuffer[recvMsgsize]='\0';
fprintf(fp,"%s",echoBuffer);
}
printf("file received and the socket closed \n");
close(cIntsock);
fclose(fp);
return(0);
}

RSCLIENT.C
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#define BUF 256
int main(int argc,char **argv)
{
int sock;
struct sockaddr_in echoServAddr;
char *servIP,*filename,echoBuffer[32];
int bytesRcvd,portno;
FILE *fp;
servIP=argv[1];
filename=argv[2];
portno=atoi(argv[3]);
fp=fopen(filename,"r");
sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
memset(&echoServAddr,0,sizeof(&echoServAddr));

27
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

echoServAddr.sin_family=AF_INET;
echoServAddr.sin_addr.s_addr=inet_addr(servIP);
echoServAddr.sin_port=htons(portno);
connect(sock,(struct sockaddr*)&echoServAddr,sizeof(echoServAddr));
while(!feof(fp))
{
fgets(echoBuffer,BUF,fp);
send(sock,echoBuffer,strlen(echoBuffer),0);
}
printf("the %s send over rs232 \n",filename);
close(sock);
return 0;
}

OUTPUT:

SOURCE.TXT
Welcome to RS232C File Transfer Program.

CLIENT
./a.out 192.168.1.111 source.txt 8000
The Source.txt send over rs232

SERVER
Server waiting for client onport:8000
File received and socket closed

RESULT:
Thus the Java program for file transfer between client and server using RS232C is
executed and the output is verified successfully.

28
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 8b FILE TRANSFER BETWEEN CLIENT AND SERVER USING TCP/IP

AIM:
To write a C program for transferring a file between two computers using TCP/IP.

ALGORITHM:

SERVER:
Step 1:Start the program.
Step 2:Create an unnamed socket for the server using parameters AF_INET as
domain and SOCK_STREAM as type.
Step 3:Get the server port number.
Step 4:Register the host address to the system by using bind() system call in server
side.
Step 5:Create a connection queue and wait for clients using listen() system call with
the number of clients requests as parameter.
Step 6:Create a Child process using fork( ) system call.
Step 7:If the process identification number is equal to zero accept the connection
using accept( ) system call when the client request for connection.
Step 8:If pid is not equal to zero then exit the process.
Step 9:Stop the Program execution.
CLIENT:
Step 1:Start the program.
Step 2:Create an unnamed socket for the client using parameters AF_INET as
domain and SOCK_STREAM as type.
Step 3:Get the client port number.
Step 4:Now connect the socket to server using connect( ) system call.
Step 5:Enter the file name.
Step 6:The file is transferred from client to server using send ( ) function.
Step 7:Print the contents of the file in a new file.
Step 8:Stop the program.

CODING:

SERVER
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
main()
{
FILE *fp;
int sd,newsd,ser,n,a,cli,pid,bd,port,clilen;
char name[100],fileread[100],fname[100],ch,file[100],rcv[100];
struct sockaddr_in servaddr,cliaddr;
printf("Enter the port address: ");
scanf("%d",&port);

29
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

sd=socket(AF_INET,SOCK_STREAM,0);
if(sd<0)
printf("Can't Create \n");
else
printf("Socket is Created\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(port);
a=sizeof(servaddr);
bd=bind(sd,(struct sockaddr*)&servaddr,a);
if(bd<0)
printf(" Can't Bind\n");
else
printf("\n Binded\n");
listen(sd,5);
clilen=sizeof(cliaddr);
newsd=accept(sd,(struct sockaddr*)&cliaddr,&clilen);
if(newsd<0)
printf("Can't Accept\n");
else
printf("Accepted\n");
n=recv(newsd,rcv,100,0);
rcv[n]='\0';
fp=fopen(rcv,"r");
if(fp==NULL)
{
send(newsd,"error",5,0);
close(newsd);
}
else
{
while(fgets(fileread,sizeof(fileread),fp))
{
if(send(newsd,fileread,sizeof(fileread),0)<0)
{
printf("Can't send\n");
}
sleep(1);
}
if(!fgets(fileread,sizeof(fileread),fp))
{
send(newsd,"completed",999999999,0);
}
return(0);
}
}

30
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

CLIENT
#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
main()
{
FILE *fp;
int csd,n,ser,s,cli,cport,newsd;
char name[100],rcvmsg[100],rcvg[100],fname[100];
struct sockaddr_in servaddr;
printf("Enter the port");
scanf("%d",&cport);
csd=socket(AF_INET,SOCK_STREAM,0);
if(csd<0)
{
printf("Error...");
exit(0);
}
else
printf("Socket is Created...\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);servaddr.sin_port=htons(cport);
if(connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("Error in Connection...\n");
else
printf("Connected...\n");
printf("Enter the existing file name: ");
scanf("%s",name);
printf("\nEnter the new filename: ");
scanf("%s",fname);
fp=fopen(fname,"w");
send(csd,name,sizeof(name),0);
while(1)
{
s=recv(csd,rcvg,100,0);
rcvg[s]='\0';
if(strcmp(rcvg,"error")==0)
printf("File is not Available...\n");
if(strcmp(rcvg,"completed")==0) {
printf("file is transferred...\n");
fclose(fp);
close(csd);
break;
}
else
fputs(rcvg,stdout);

31
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

fprintf(fp,"%s",rcvg);
}
}

OUTPUT:

Server Side
[1me16@localhost ~]$ cc ftpclient.c
[1me16@localhost ~]$. /a.out
Enter the port address:
8663
Socket is Created
Binded
Connected…
Client Side
[1me16@localhost ~]$ cc ftpserver.c
[1me16@localhost ~]$. /a.out
Socket is Created..
Connected
Enter the existing file name: net
Enter the new file name: network
Welcome to Network Lab
File is transferred...

RESULT:
Thus the C program for transferring file from one machine to another machine using TCP
is executed and the output is verified successfully.

32
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 9 IMPLEMENTING REMOTE METHOD INVOCATION

AIM:
To implement Remote Method Invocation using Java.

ALGORITHM:
Step 1: Start the program.
Step 2: Create the remote interface.
Step 3: Provide the implementation of the remote interface.
Step 4: Create the stub and skeleton objects using rmic tool.
Step 5: Start the registry service by rmiregistry tool.
Step 6: Create and run the server application.
Step 7: Create and run the client application.

CODING:

ADDER.JAVA
import java.rmi.*;
public interface Adder extends Remote{
public int add(int x,int y)throws RemoteException;
}

ADDERREMOTE.JAVA
import java.rmi.*;
import java.rmi.server.*;
public class AdderRemote extends UnicastRemoteObject implements Adder{
AdderRemote()throws RemoteException{
super();
}
public int add(int x,int y){return x+y;}
}

RMISERVER.JAVA
import java.rmi.*;
import java.rmi.registry.*;
public class RmiServer{
public static void main(String args[]){
try{
Adder stub=new AdderRemote();
Naming.rebind("rmi://localhost:5000/rmiex",stub);
}catch(Exception e){System.out.println(e);}
}
}

33
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

RMICLIENT.JAVA
import java.rmi.*;
public class RmiClient{
public static void main(String args[]){
try{
Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/rmiex");
System.out.println(stub.add(34,4));
}catch(Exception e){}
}
}

OUTPUT:

javac RmiServer.java

javac RmiClient.java

rmic AdderRemote

rmiregistry 5000

java RmiServer

java RmiClient

38

RESULT:
Thus the Java program for implementing Remote Method Invocation is executed and the
output is verified successfully.

34
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 10 BROADCAST/ MULTICAST A MESSAGE TO A GROUP IN THE SAME


NETWORK

AIM:
To write a network program to broadcast/multicast a message to a group in the same
network using Java.

ALGORITHM:

CLIENT:
Step 1: Import awt, swing packages.
Step 2: Create the frame and define necessary parameters for frame
Step 3: Use the InetAddress.getByName to get another host name using sockets.
Step 4: Using socket get the local host address from client
Step 5: Close the socket

SERVER:
Step 1: Create the socket connection
Step 2: Get the new client connection through InetAddress get by client
Step 3: Open the connection to new client using IO Buffer stream
Step 4: Close the connection

CODING:

CLIENT
import java.io.*;
import javax.swing.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class multiclient extends Panel
{
TextArea receivedText;
Socket sock;
private GridBagConstraints c;
private GridBagLayout gridBag;
private Frame frame;
private Label label;
JButton send;
JButton exit;
private int port=5001;
private TextArea sendText;
private String hostname;
private String username;
private DataOutputStream remoteOut;

35
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

ImageIcon i1,i2;
public static void main(String args[])
{
if(args.length != 2)
{
System.out.println("Format is : java multiclient ");
return;
}
Frame f1=new Frame("Welcome Protocol");
f1.resize(800,600);
f1.show();
JOptionPane.showMessageDialog(f1,"Welcome "+args[0]+".. Have a
niceSession.","Welcome",0);
Frame f= new Frame("Connecting to Mr. "+args[0]);
multiclient chat=new multiclient(f,args[0],args[1]);
f.add("Center",chat);
f.setSize(800,600);
f.show();
chat.client();
}
public multiclient(Frame f,String user,String host)
{
frame=f;
frame.addWindowListener(new WindowExitHandler());
username=user;
hostname=host;
//Insets insets=new Insets(10,20,5,10);
//gridBag=new GridBagLayout();
//setLayout(gridBag);
/*c=new GridBagConstraints();
c.insets=insets;
c.gridy=0;
c.gridx=0;*/
label=new Label("Text to send :");
add(label);
/*gridBag.setConstraints(label,c);
c.gridx=1;*/
sendText=new TextArea(15,30);
/*sendText.addActionListener(new TextActionHandler());
gridBag.setConstraints(sendText,c);*/
add(sendText);
//c.gridy=1;
//c.gridx=0;
label= new Label("Text received :");
//gridBag.setConstraints(label,c);
add(label);

36
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

//c.gridx=1;
receivedText=new TextArea(15,30);
//gridBag.setConstraints(receivedText,c);
add(receivedText);
ImageIcon i1=new ImageIcon("click.gif");
ImageIcon i2=new ImageIcon("doorin2.gif");
send=new JButton(i1);
exit=new JButton(i2);
add(send);
add(exit);
send.addActionListener(new TextActionHandler());
exit.addActionListener(new EXIT());
}
void client()
{
try
{
if(hostname.equals("local"))
hostname=null;
InetAddress serverAddr= InetAddress.getByName(hostname);
sock=new Socket(serverAddr.getHostName(),port);
remoteOut=new DataOutputStream(sock.getOutputStream());
System.out.println("Connected to server " + serverAddr.getHostName() + "on port " +
sock.getPort());
new multiclientReceive(this).start();
}
catch(IOException e)
{
System.out.println(e.getMessage() + " : Failed to connect to server.");
}
}
protected void finalize() throws Throwable
{
try
{
if(remoteOut != null)
remoteOut.close();
if(sock != null)
sock.close();
}
catch(IOException x)
{}
super.finalize();
}
class WindowExitHandler extends WindowAdapter
{

37
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

public void windowClosing(WindowEvent e)


{
Window w=e.getWindow();
w.setVisible(false);
w.dispose();
System.exit(0);
}
}

class EXIT implements ActionListener


{
public void actionPerformed(ActionEvent e)
{
if((JOptionPane.showConfirmDialog(new Frame(),"Are You Sure to close the
Session?"))==JOptionPane.YES_OPTION)
{
System.exit(0);
}

}
}
class TextActionHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
remoteOut.writeUTF(sendText.getText());
sendText.setText("");
}
catch(IOException x)
{
System.out.println(x.getMessage() + " : connection to peer lost.");
}
}
}
}
class multiclientReceive extends Thread
{
private multiclient chat;
multiclientReceive(multiclient chat)
{
this.chat=chat;
}
public synchronized void run()
{

38
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

String s;
DataInputStream remoteIn=null;
try
{
remoteIn= new DataInputStream(chat.sock.getInputStream());
while(true)
{
s=remoteIn.readUTF();
chat.receivedText.setText(s);
}
}
catch(IOException e)
{
System.out.println(e.getMessage() + " : connection to peer lost.");
}
finally
{
try
{
if(remoteIn !=null)
remoteIn.close();
}
catch(IOException x)
{}
}
}
}
SERVER
import java.io.*;
import java.net.*;
import java.util.Vector;
import java.util.Enumeration;
public class multiserver
{
//static String k=socket.getInetAddress().getHostName();
private int port=8080;
private boolean li=true;
private Vector clients=new Vector();
public static void main(String a[])
{
System.out.println(" Press ctrl-c to Quit.");
new multiserver().server();
}
void server()
{
ServerSocket serverSock=null;

39
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

try
{
InetAddress serverAddr=InetAddress.getByName(null);
System.out.println("Waiting for"+serverAddr.getHostName()+"onport"+port);
serverSock=new ServerSocket(port,8080);
}
catch(IOException e)
{
System.out.println(e.getMessage()+":Failed");
return;
}
while(li)
{
try
{
Socket socket=serverSock.accept();
System.out.println("Accept"+socket.getInetAddress().getHostName());
DataOutputStream remoteOut= new DataOutputStream(socket.getOutputStream());
clients.addElement(remoteOut);
new ServerHelper(socket,remoteOut,this).start();
}
catch(IOException e)
{
System.out.println(e.getMessage()+":Failed");
}
}
if(serverSock !=null)
{
try
{
serverSock.close();
}
catch(IOException x)
{
}
}
}
synchronized Vector getClients()
{
return clients;
}
synchronized void removeFromClients(DataOutputStream remoteOut)
{
clients.removeElement(remoteOut);
}
}

40
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

class ServerHelper extends Thread


{
private Socket sock;
private DataOutputStream remoteOut;
private multiserver server;
private boolean li=true;
private DataInputStream remoteIn;
ServerHelper(Socket sock,DataOutputStream remoteOut,multiserver
server) throws IOException
{
this.sock=sock;
this.remoteOut=remoteOut;
this.server=server;
remoteIn=new DataInputStream(sock.getInputStream());
}
public synchronized void run()
{
String s;
try
{
while(li)
{
s=remoteIn.readUTF();
broadcast(s);
}
}
catch(IOException e)
{
System.out.println(e.getMessage()+"connection lost");
}
finally
{
try
{
cleanUp();
}
catch (IOException x)
{
}
}
}
private void broadcast(String s)
{
Vector clients=server.getClients();
DataOutputStream dataOut=null;
for(Enumeration e=clients.elements();

41
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

e.hasMoreElements(); )
{
dataOut=(DataOutputStream)(e.nextElement());
if(!dataOut.equals(remoteOut))
{
try
{
dataOut.writeUTF(s);
}
catch(IOException x)
{
System.out.println(x.getMessage()+"Failed");
server.removeFromClients(dataOut);
}
}
}
}
private void cleanUp() throws IOException
{
if(remoteOut!=null)
{
server.removeFromClients(remoteOut);
remoteOut.close();
remoteOut=null;
}
if(remoteIn!=null)
{
remoteIn.close();
remoteIn=null;
}
if(sock!=null)
{
sock.close();
sock=null;
}
}
protected void finalize() throws Throwable
{
try
{
cleanUp();
}
catch(IOException x)
{
}
super.finalize();

42
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

}
}

OUTPUT:

RESULT:

Thus the program for broadcast / multicast a message in the same network is executed
and the output is verified.

43
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

EX. NO. 11 DEMONSTRATION OF NETWORK SIMULATORS

AIM:

To demonstrate the usage of Network Simulators.

NETWORK SIMULATORS:

PACKET TRACER:

Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that
allows users to create network topologies and imitate modern computer networks. The software
allows users to simulate the configuration of Cisco routers and switches using a simulated
command line interface. Packet Tracer makes use of a drag and drop user interface, allowing
users to add and remove simulated network devices as they see fit. The software is mainly
focused towards Certified Cisco Network Associate Academy students as an educational tool for
helping them learn fundamental CCNA concepts.

Packet Tracer can be run on Linux and Microsoft Windows. Similar Android and iOS
apps are also available. Packet Tracer allows users to create simulated network topologies by
dragging and dropping routers, switches and various other types of network devices. A “cable”
item represents a physical connection between devices. Packet Tracer supports an array of
simulated Application Layer protocols, as well as basic routing with RIP, OSPF, EIGRP, BGP,
to the extents required by the current CCNA curriculum. As of version 5.3, Packet Tracer also
supports the Border Gateway Protocol.

Packet Tracer allows students to design complex and large networks, which is often not
feasible with physical hardware, due to costs. CCNA Academy students commonly use packet
Tracer since it is available to them free. However, due to functional limitations, it is intended by
CISCO to be used only as a learning aid, not a replacement for Cisco routers and switches. The
application itself only has a small number of features found within the actual hardware running a
current Cisco IOS version. Thus, Packet Tracer is unsuitable for modelling production networks.
It has a limited command set, meaning it is not possible to practice all of the IOS commands that
might be required. Packet Tracer can be useful for understanding abstract networking concepts,
such as the Enhanced Interior Gateway Routing Protocol by animating these elements in a visual
form. Packet Tracer is also useful in education by providing additional components, including an
authoring system, network protocol simulation and improving knowledge an assessment system.

NS2:

The network simulator (also popularly called ns-2, in reference to its current generation)
is a discrete event network simulator. It is popular in academia for its extensibility (due to its

44
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

open source model) and plentiful online documentation. It is popularly used in the simulation of
routing and multicast protocols, among others, and is heavily used in ad-hoc networking
research. It supports an array of popular network protocols, offering simulation results for wired
and wireless networks alike. It can be also used as limited-functionality network emulator. It is
licensed for use under version 2 of the GNU General Public License.

NS was built in C++ and provides a simulation interface through OTcl, an object oriented
dialect of Tcl. The user describes a network topology by writing OTcl scripts, and then the main
ns program simulates that topology with specified parameters. The NS2 makes use of flat earth
model in which it assumes that the environment is flat without any elevations or depressions.
However, the real world does have geographical features like valleys and mountains. NS2 fails to
capture this model in it.

Many researchers have proposed the additions of new models to NS2. Shadowing Model
in NS2 attempts to capture the shadow effect of signals in real life, but does that inaccurately.
NS2's shadowing model does not consider correlations: a real shadowing effect has strong
correlations between two locations that are close to each other. Shadow fading should be
modeled as a two dimensional log-normal random process with exponentially decaying spatial
correlations.

Generation 3 of ns has begun development as of July 1, 2006 and is projected to take four
years. It is funded by the institutes like University of Washington, Georgia Institute of
Technology and the ICSI Center for Internet Research with collaborative support from the
Planète research group at INRIA Sophia-Antipolis. Currently ns-3 is in development phase. It is
an event based network simulator. (http://www.wikipedia.org/ns.htm).

GLOMOSIM:

Global Mobile Information System Simulator (GloMoSim) is a network protocol simulation


software that simulates wireless and wired network systems. GloMoSim is designed using the
parallel discrete event simulation capability provided by Parsec, a parallel programming
language. GloMoSim currently supports protocols for a purely wireless network. It uses the
Parsec compiler to compile the simulation protocols.

In GloMoSim we are building a scalable simulation environment for wireless and wired
network systems. It is being designed using the parallel discrete-event simulation capability
provided by Parsec. GloMoSim currently supports protocols for a purely wireless network. In the
future, we anticipate adding functionality to simulate a wired as well as a hybrid network with
both wired and wireless capabilities.

45
B.Tech-CSE Network Programming Lab (Staff Manual)-2017 BCS18L05

Most network systems are currently built using a layered approach that is similar to the
OSI seven layer network architecture. The plan is to build GloMoSim using a similar layered
approach. Standard APIs will be used between the different simulation layers. This will allow the
rapid integration of models developed at different layers by different people.

OPNET:

OPNET Technologies, Inc. provides network and application management software and
hardware, as well as associated services. The company was founded in 1986 and went public in
2000. It is headquartered in Bethesda, Maryland and has offices in Cary, North Carolina;
Nashua, New Hampshire; Dallas, Texas; and Santa Clara, California. It has international offices
in Slough, United Kingdom; Paris, France; Ghent, Belgium; Frankfurt, Germany; and Singapore
with staff and consultants in multiple locations in Asia and Latin America. Representative
customers include Capital One, Cox Communications, CVS, France Telecom, GEICO Insurance,
Merck, NBC Universal, and Oracle.

OPNET is a simulator built on top of a discrete event system. It simulates the system
behavior by modeling each event happening in the system and processes it by user-defined
processes. It uses a hierarchical strategy to organize all the models to build a whole network. The
hierarchy models entities from physical link transceivers, antennas, to CPU running processes to
manage queues or running protocols, to devices modeled by nodes with process modules and
transceivers, to network model that connects all different kinds of nodes together. OPNET also
provides programming tools for us to define any type of packet format we want to use in our own
protocols. Programming in OPNET includes the following major tasks: define protocol packet
format, define the state transition machine for processes running the protocol, define process
modules and transceiver modules we need in each device node, finally define the network model
by connecting the device nodes together using user-defined link models.

RESULT:

Thus the various Network Simulators has been studied.

46

You might also like