You are on page 1of 42

EC8563 -COMMUNICATION NETWORKS LAB

1
EC8563 -COMMUNICATION NETWORKS LAB

EX.NO DATE LIST OF EXPERIMENTS Page No. Staff Initial

2
EC8563 -COMMUNICATION NETWORKS LAB

3
EC8563 -COMMUNICATION NETWORKS LAB

EX.NO:1
DATE:
IMPLEMENTATION OF ERROR DETECTION / ERROR CORRECTION TECHNIQUES

AIM:
Write a program for error detection and error correction techniques by Hamming Method using
C language.

APPARATUS REQUIERD:

 C -editor

 Standalone desktop.

PROCEDURE:

1. Start the program.


2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.

4
EC8563 -COMMUNICATION NETWORKS LAB

PROGRAM FOR HAMMING METHOD :

#include<stdio.h>
#include<conio.h>
Void main() {
int data[7],rec[7],i,c1,c2,c3,c;
printf ("this works for message of 4bits in size \n enter message bit one by one: ");
scanf ("%d %d %d %d",& data[0],&data[1],&data[2],&data[4]); data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4]; data[3]=data[0]^data[1]^data[2];
printf("\n the encoded bits are given below: \n");
for (i=0;i<7;i++) {
printf("%d ",data[i]);
}
printf("\n enter the received data bits one by one: "); for (i=0;i<7;i++) {
scanf("%d",& rec[i]);
}
c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf ("\n congratulations there is no error: "); } else {
printf("\n error on the position: %d\n the correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1; else
rec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d ",rec[i]);
}
}
getch();
}
}

5
MODEL OUTPUT:

RESULT:

Thus the Error detection and correction methods were executed and verified
successfully by using c – editor.

EX.NO:2
DATE:
IMPLEMENTATION OF STOP AND WAIT PROTOCOL
AIM:

To write a program for talk commands using socket programming to send and receive message
from client and server using connection oriented service.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

PROCEDURE:
Server:

1. Start the program.


2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “end” is encountered, exit both
the programs.
8. Stop the program.

Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program

SENDER PROGRAM :

import java.io.*;
import java.net.*;
public class Sender{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
public void run(){
 try{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Waiting for Connection....");
 sender = new Socket("localhost",2004);
sequence=0;
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
 in=new ObjectInputStream(sender.getInputStream());
 str=(String)in.readObject();
 System.out.println("reciver     > "+str);
System.out.println("Enter the data to send....");
packet=br.readLine();
n=packet.length();
do{
try{
 if(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
}
else if(i==n){
 msg="end";out.writeObject(msg);break;
}
out.writeObject(msg);
sequence=(sequence==0)?1:0;
out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
System.out.println("waiting for ack.....\n\n");
if(ack.equals(String.valueOf(sequence))){
i++;
System.out.println("receiver   >  "+" packet recieved\n\n");
}
else{     
System.out.println("Time out resending data....\n\n");
sequence=(sequence==0)?1:0;
}
}catch(Exception e){}
}while(i<n+1);
System.out.println("All data sent. exiting.");
}catch(Exception e){}
finally{
try{
in.close();
out.close();
sender.close();
}
catch(Exception e){}
}
}
public static void main(String args[]){
Sender s=new Sender ();
s.run();
}
}

RECEIVER PROGRAM

import java.io.*;
import java.net.*;
public class Reciever{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Reciever(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2004,10);
System.out.println("waiting for connection...");
connection=reciever.accept();
sequence=0;
System.out.println("Connection established   :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected    .");

do{
try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver         >"+packet);
}
else
{
System.out.println("\n\nreceiver         >"+packet +"   duplicate data");
}
if(i<3){
out.writeObject(String.valueOf(sequence));i++;
}
else{
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}
}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended    .");
}
catch(Exception e){}
finally{
try{
in.close();
out.close();
reciever.close();
}
catch(Exception e){}
}
}
public static void main(String args[]){
Reciever s=new Reciever();
while(true){
s.run();
}
}
}
SENDER OUTPUT

Waiting for Connection....


receiver > connected     .
Enter the data to send....
my name
data sent>0m
waiting for ack.....
receiver        >   packet received
data sent>1y
waiting for ack.....
receiver        >   packet received
data sent>0n
waiting for ack.....
receiver        >   packet received
data sent>1a
waiting for ack.....
Time out resending data....
data sent>1a
waiting for ack.....
receiver        >   packet received
data sent>0m
waiting for ack.....
receiver        >   packet received
data sent>1e
waiting for ack.....
receiver        >   packet received
All data sent. exiting.

RECEIVER OUTPUT
waiting for connection...
Connection established  :
receiver        >0m
receiver        >1y
receiver        >0n
receiver        >1a
receiver        >1a   duplicate data
receiver        >0m
receiver        >1e
Data received=my name
waiting for connection...

RESULT:

Thus the java Socket Program for stop and Wait Protocol executed and output is verified
Successfully.
EX.NO:3
DATE:
IMPLEMENTATION OF SLIDING WINDOW GO BACK N

AIM:

Write a program in Java to implement Go Back N algorithm. The Program sends the frames
from the Client to the Server with checking for missing frames via sending an acknowledgement.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

PROCEDURE:
Server:

1. Start the program.


2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “end” is encountered, exit both
the programs.
8. Stop the program.

Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program
SENDER PROGRAM :
import java.net.*;
import java.io.*;
import java.util.*;
public class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket server=new ServerSocket(6262);
System.out.println(“Server established.”);
Socket client=server.accept();
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
System.out.println(“Client is now connected.”);
int x=(Integer)ois.readObject();
int k=(Integer)ois.readObject();
int j=0;
int i=(Integer)ois.readObject();
boolean flag=true;
Random r=new Random(6);
int mod=r.nextInt(6);
while(mod==1||mod==0)
mod=r.nextInt(6);
while(true)
{
int c=k;
for(int h=0;h<=x;h++)
{
System.out.print(“|”+c+”|”);
c=(c+1)%x;
}
System.out.println();
System.out.println();
if(k==j)
{
System.out.println(“Frame “+k+” recieved”+”\n”+”Data:”+j);
j++;
System.out.println();
}

else
System.out.println(“Frames recieved not in correct order”+”\n”+” Expected farme:” + j +”\n”+ ”
Recieved frame no :”+ k);
System.out.println();
if(j%mod==0 && flag)
{
System.out.println(“Error found. Acknowledgement not sent. “);
flag=!flag;
j–;
}
else if(k==j-1)
{
oos.writeObject(k);
System.out.println(“Acknowledgement sent”);
}
System.out.println();
if(j%mod==0)
flag=!flag;
k=(Integer)ois.readObject();
if(k==-1)
break;
i=(Integer)ois.readObject();
}
System.out.println(“Client finished sending data. Exiting”);
oos.writeObject(-1);
}
}

CLIENT PROGRAM :
import java.util.*;
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Enter the value of m : “);
int m=Integer.parseInt(br.readLine());
int x=(int)((Math.pow(2,m))-1);
System.out.print(“Enter no. of frames to be sent:”);
int count=Integer.parseInt(br.readLine());
int data[]=new int[count];
int h=0;
for(int i=0;i<count;i++)
{
System.out.print(“Enter data for frame no ” +h+ ” => “);
data[i]=Integer.parseInt(br.readLine());
h=(h+1)%x;
}
Socket client=new Socket(“localhost”,6262);
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
System.out.println(“Connected with server.”);
boolean flag=false;
GoBackNListener listener=new GoBackNListener(ois,x);
listener=new GoBackNListener(ois,x);
listener.t.start();
int strt=0;
h=0;
oos.writeObject(x);
do
{
int c=h;
for(int i=h;i<count;i++)
{
System.out.print(“|”+c+”|”);
c=(c+1)%x;
}
System.out.println();
System.out.println();
h=strt;
for(int i=strt;i<x;i++)
{
System.out.println(“Sending frame:”+h);
h=(h+1)%x;
System.out.println();
oos.writeObject(i);
oos.writeObject(data[i]);
Thread.sleep(100);
}
listener.t.join(3500);
if(listener.reply!=x-1)
{
System.out.println(“No reply from server in 3.5 seconds. Resending data from frame no ” +
(listener.reply+1));
System.out.println();
strt=listener.reply+1;
flag=false;
}
else
{
System.out.println(“All elements sent successfully. Exiting”);
flag=true;
}
}while(!flag);
oos.writeObject(-1);
}
}

class GoBackNListener implements Runnable


{
Thread t;
ObjectInputStream ois;
int reply,x;
GoBackNListener(ObjectInputStream o,int i)
{
t=new Thread(this);
ois=o;
reply=-2;
x=i;
}
@Override
public void run() {
try
{
int temp=0;

while(reply!=-1)
{

reply=(Integer)ois.readObject();
if(reply!=-1 && reply!=temp+1)
reply=temp;
if(reply!=-1)
{
temp=reply;
System.out.println(“Acknowledgement of frame no ” + (reply%x) + ” recieved.”);
System.out.println();
}
}
reply=temp;
}
catch(Exception e)
{
System.out.println(“Exception => ” + e);
}
}
}

CLIENT OUTPUT:

Enter the value of m : 7


Enter no. of frames to be sent:5
Enter data for frame no 0 => 1
Enter data for frame no 1 => 2
Enter data for frame no 2 => 3
Enter data for frame no 3 => 4
Enter data for frame no 4 => 5
Connected with server.
|0||1||2||3||4|
Sending frame:0
Acknowledgement of frame no 0 recieved.
Sending frame:1
Sending frame:2
Sending frame:3
Sending frame:4
Sending frame:5

SERVER OUTPUT:
Server established.
Client is now connected.
|0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||
32||33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||
61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||
90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||
114||115||116||117||118||119||120||121||122||123||124||125||126||0|
Frame 0 recieved
Data:0
Acknowledgement sent

|1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||
33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||
62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||
91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1|
Frame 1 recieved
Data:1
Error found. Acknowledgement not sent.

|2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||
34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||
63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||
92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1||2|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :2

|3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||
34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||
63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||
92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1||2||3|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :3

|4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||
35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||
64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||
93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||
116||117||118||119||120||121||122||123||124||125||126||0||1||2||3||4|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :4

 RESULT:

Thus the Sliding Window Go Back N & LAN port interface was implemented and the

parameters measured by using LAN-T simulation software.

EX.NO:4
DATE:
IMPLEMENTATION AND STUDY OF SLIDING WINDOW
SELECTIVE REPEAT PROTOCOL

AIM:

To write a program for sliding window selective repeat Protocol programming to send and
receive message from client and server using connection oriented service.
APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

SENDER PROGRAM :

import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
{
public static void main(String a[])throws Exception
{
ServerSocket ser=new ServerSocket(10);
Socket s=ser.accept();
DataInputStream in=new DataInputStream(System.in);
DataInputStream in1=new DataInputStream(s.getInputStream());
String sbuff[]=new String[8];
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
do
{
p=new PrintStream(s.getOutputStream());
System.out.print("Enter the no. of frames : ");
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=sws-1)
{
System.out.println("Enter "+nf+" Messages to be send\n");
for(i=1;i<=nf;i++)
{
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
}
sws-=nf;
System.out.print("Acknowledgment received");
ano=Integer.parseInt(in1.readLine());
System.out.println(" for "+ano+" frames");
sws+=nf;
}
else
{
System.out.println("The no. of frames exceeds window size");
break;
}
System.out.print("\nDo you wants to send some more frames : ");
ch=in.readLine(); p.println(ch);
}
while(ch.equals("yes"));
s.close();
}
}

RECEIVER PROGRAM:
import java.net.*;
import java.io.*;
class slidreceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10);
 DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch; System.out.println();
do
{
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
{
for(i=1;i<=nf;i++)
{
rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr+1); rws+=nf; }
else
break;
ch=in.readLine();
}
while(ch.equals("yes"));
}

SENDER OUTPUT:
Enter the no. of frames: 4
Enter 4 Messages to be send

hiii
how r u
i am fine
how is everyone
Acknowledgment received for 4 frames

Do you wants to send some more frames: no

RECEIVER OUTPUT:
The received Frame 0 is : hiii
The received Frame 1 is : how r u
The received Frame 2 is : i am fine
The received Frame 3 is : how is everyone

Acknowledgment sent

RESULT:

Thus the Java Socket Program for stop and Wait Protocol executed and output is verified
successfully

EX.NO:5
DATE:
IMPLENTATION OF IP ADDRESS CONFIGURATION

AIM:

To write a program for implementation of IP address configuration.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

PROGRAM:
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;
  
public class JavaProgram
{
    public static void main(String args[]) throws Exception
    {
        // Returns the instance of InetAddress containing
        // local host name and address
        InetAddress localhost = InetAddress.getLocalHost();
        System.out.println("System IP Address : " +
                      (localhost.getHostAddress()).trim());
  
        // Find public IP address
        String systemipaddress = "";
        try
        {
            URL url_name = new URL("http://bot.whatismyipaddress.com");
  
            BufferedReader sc =
            new BufferedReader(new InputStreamReader(url_name.openStream()));
  
            // reads system IPAddress
            systemipaddress = sc.readLine().trim();
        }
        catch (Exception e)
        {
            systemipaddress = "Cannot Execute Properly";
        }
        System.out.println("Public IP Address: " + systemipaddress +"\n");
    }
}

OUTPUT:

System IP Address : 10.0.8.204


Public IP Address : 35.166.48.97
RESULT:

Thus the java socket program for IP address configuration executed and output is verified
successfully
EX.NO:6
DATE:
WRITE A SOCKET PROGRAM FOR NSLOOKUP COMMANDS

AIM:

To write a java program for nslookup commands of socket programming.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

PROGRAM:

import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* An "nslookup" clone in Java.
*
* @author Elliot Rusty Harold, O'Reilly & Associates
*/
public class JavaLookup {

public static void main(String args[]) {

if (args.length > 0) { // use command line


for (int i = 0; i < args.length; i++) {
lookup(args[i]);
}
} else {
DataInputStream myInputStream = new DataInputStream(System.in);
System.out
.println("Enter names and IP addresses. Enter \"exit\" to quit.");
while (true) {
String s;
try {
s = myInputStream.readLine();
} catch (IOException e) {
break;
}
if (s.equals("exit"))
break;
if (s.equals("quit"))
break;
if (s.charAt(0) == '\004')
break; // unix ^D
lookup(s);
}

} /* end main */

private static void lookup(String s) {

InetAddress thisCOMMUNICATION;
byte[] address;

// get the bytes of the IP address


try {
thisCOMMUNICATION = InetAddress.getByName(s);
address = thisCOMMUNICATION.getAddress();
} catch (UnknownHostException ue) {
System.out.println("Cannot find host " + s);
return;
}

if (isHostname(s)) {
// Print the IP address
for (int i = 0; i < address.length; i++) {
int unsignedByte = address[i] < 0 ? address[i] + 256
: address[i];
System.out.print(unsignedByte + ".");
}
System.out.println();
} else { // this is an IP address
try {
System.out.println(InetAddress.getByName(s));
} catch (UnknownHostException e) {
System.out.println("Could not lookup the address " + s);
}
}

} // end lookup

private static boolean isHostname(String s) {


char[] ca = s.toCharArray();
// if we see a character that is neither a digit nor a period
// then s is probably a hostname
for (int i = 0; i < ca.length; i++) {
if (!Character.isDigit(ca[i])) {
if (ca[i] != '.') {
return true;
}
}
}

// Everything was either a digit or a period


// so s looks like an IP address in dotted quad format
return false;

} // end isHostName

} // end javalookup

RESULT:

Thus the java Socket Program for nslookup commands is executed and output is verified
successfully.

EX.NO:7
DATE:

WRITE A SOCKET PROGRAM FOR PING COMMANDS

AIM:
To write a java program for Ping commands of socket programming.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop.

PROCEDURE:

SERVER:

1. Start the program.


2. Import java.net and other necessary packages.
3. Initialize the ping server with both sockets as null value.
4. Start the server socket.
5. At the client give the IP address of the server.
6. The client program is then started by starting socket.
7. At the receiver end, the client is pinged.
8. Stop the program.
CLIENT:

1. Start the program.


2. Import java.net and other necessary packages.
3. Initialize the ping client with both sockets as null value.
4. Start the socket.
5. Get the IP address of the server.
6. Ping the server.
7. At the receiver end, the server is pinged.
8. Stop the program.
SERVER PROGRAM:
import java.io.*;
import java.net.*;
public class pingserver
{
public static void main(String a[])
{
String line1,line2;
int i;
ServerSocket es;
DataInputStream di;
PrintStream ps;
Socket csoc;
es=null;
csoc=null;
try
{
es=new ServerSocket(9999);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("ping server");
try
{
csoc=es.accept();
di=new DataInputStream(csoc.getInputStream());
ps=new PrintStream(csoc.getOutputStream());
for(i=0;i<4;i++)
{
line1=di.readLine();
System.out.println("pinged by client");
ps.println(line1+"reply from host:bytes=3<time<1ms TT<=128");
}
di.close();
ps.close();}
catch(Exception e)
{
System.out.println(e);
}}}
CLIENT PROGRAM:

import java.io.*;
import java.net.*;
public class pingclient
{
public static void main(String args[])
{
PrintWriter out=null;
int i,j,k;
BufferedReader networkIn=null;
try
{
System.out.println("enter the IP address:"); DataInputStream in = new
DataInputStream(System.in);
String ip = in.readLine();
Socket thesocket = new Socket(ip, 9999);
networkIn = new BufferedReader(new
InputStreamReader(System.in));
out = new PrintWriter(thesocket.getOutputStream());
System.out.println("\npinging" + ip + "with 32 bytes ofdata\n");
for (i = 0; i < 4; i++)
{
out.println(ip);
out.flush();
String inp = networkIn.readLine();
if (inp != null)
{
for (j = 0; j < 10000; j++)
{
for (k = 0; k < 50000; k++)
{
}
}
System.out.println("reply from" + inp);
}
else
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 10000; j++)
{
for (k = 0; k < 50000; k++)
{
}
System.out.println("\nrequest time out")

}
catch (IOException e)
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 1000; j++)
{
for (k = 0; k < 5000; k++)
{
}
}
System.out.println("\nrequest timed out");
}
}
try{
if(networkIn!=null)
networkIn.close();
if(out!=null)
out.close();
}
catch(Exception e){
System.out.println("\nrequested time out");
}
}
OUT PUT:

C:\Documents and Settings\Vvit staff>cd\ C:\>cd D:\Sasi\Java


D:\Sasi\Java> set path=c:\program files\java\jdk1.6.0_02\bin
D:\Sasi\Java>javac pingclient.java
D:\Sasi\Java>java ping client

enter the IP address:


192.168.1.10
pinging192.168.1.10with 32 bytes of data 5
reply from5
8
reply from8
9
reply from9
4
reply from4
D:\Sasi\Java>
PING Server
C:\Documents and Settings\Vvit staff>cd\ C:\>cd D:\Sasi\Java
D:\Sasi\Java> set path=c:\program files\java\jdk1.6.0_02\bin
D:\Sasi\Java>javac pingserver.java
D:\Sasi\Java>java ping server

ping server
pinged by client
pinged by client
pinged by client
pinged by client
D:\Sasi\Java>

RESULT:

Thus the java Socket Program for ping Commands is executed and output is verified
successfully.
EX.NO:8
DATE:
WRITE A SOCKET PROGRAM FOR TRACEROUTE COMMANDS

AIM:

To write a java program for traceroute commands of socket programming.

APPARATUS REQUIERD:

 JDK TOOLKIT 5.0

 Standalone desktop

PROGRAM:
import java.io.*;
import java.net.*;
import java.lang.*;
class Traceroute
{
public static void main(String args[]){

BufferedReader in;

try{
Runtime r = Runtime.getRuntime();
Process p = r.exec("tracert www.google.com");

in = new BufferedReader(new InputStreamReader(p.getInputStream()));

String line;

if(p==null)
System.out.println("could not connect");

while((line=in.readLine())!=null){

System.out.println(line);

//in.close();
}

}catch(IOException e){
System.out.println(e.toString());

}
}
}

OUTPUT:
Tracing route to www.google.com [74.125.28.106]
over a maximum of 30 hops:

1 70 ms 55 ms 70 ms 10.228.129.13
2 87 ms 84 ms 10.228.149.14
3 82 ms 85 ms 116.202.226.145
4 95 ms 94 ms 136 ms 10.228.158.82
5 Request timed out.
6 53 ms 55 ms 59 ms 116.202.226.21
7 85 ms 74 ms 82 ms 72.14.205.145
8 76 ms 75 ms 71 ms 72.14.235.69
9 124 ms 114 ms 113 ms 216.239.63.213
10 181 ms 194 ms 159 ms 66.249.95.132
11 285 ms 247 ms 246 ms 209.85.142.51
12 288 ms 282 ms 283 ms 72.14.233.138
13 271 ms 283 ms 274 ms 64.233.174.97
14 Request timed out.
15 269 ms 273 ms 283 ms pc-in-f106.1e100.net [74.125.28.106]
Trace complete.

RESULT:

Thus the java Socket Program for traceroute commands is executed and output is verified
successfully.
EX.NO:9
DATE:
IMPLEMENTATION OF DATA ENCRYPTION AND DECRYPTION

.
AIM:

To implement the Encryption and Decryption of a file using RC4 algorithm.

APPARATUS REQUIERD:

 Java JDK 5.0.

 Personal COMMUNICATION.

PROCEDURE:

Initial Setup:
1. Install Java JDK 5.0.
2. Browse C:\Lantrain\DataSecurity.

3. Copy the RC4 folder and three class files (Connect, RC4Client, and

Server) and paste it into the Java\jdk1.5\bin folder in both the server and

client PC’s.

Setting up the Server:


1. Open the command prompt window (Start _Run _ type cmd).
2. Browse the java bin folder.
3. Type java Server to run the server.

Encrypting a file:
1. Open command prompt in the client side.
2. Browse the java bin folder.
3. Type java RC4Client.
4. Enter the IP address of the server.
5. Enter the mode of operation.
6. Enter the Encryption key not more than 5 characters.
7. Enter the path name of the file to be encrypted. (For e.g.: c:\\abc.txt)
8. Type YES if you like to close the session or type NO if you like to continue decrypting the
Cipher text
9.The encrypted text is available in c:\output.tx .Try to re-arrange the cipher text using any
crypt-analysis tool
Decrypting the Cipher text file:

1. Enter the mode of operation as DEC for decrypting the cipher text.
2. Enter the Decryption keys same as used for Encryption.
3. Enter the full path name of the file to be decrypted. (i.e., c:\\output.txt)
4. Find out the decrypted file in c:\\output.txt.

SETTING UP THE SERVER:


MODEL OUT PUTS OF ENCRYPTION:
MODEL OUTPUT OF DECRYPTION:

RESULT:

Thus the data encryption and decryption file using RC4 algorithm was studied and verified.
EX.NO:10
DATE:
IMPLEMENTATION OF HIGH LEVEL DATA LINK CONTROL

AIM:

To write a c program to implement a data link control for bit stuffing method by using C-editor.

APPARATUS REQUIERD:

 C -editor

 Standalone desktop.

PROCEDURE:

1. Start the program.


2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c.
5. Run the program.
6. If any error occurs in the program correct the error and again run the program.
7. Enter the data of message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM :

#include<stdio.h>
#include<conio.h>
void charc(void);
void main()
{
int choice;
while(1)
{
printf("\n\n\n1.character stuffing"); printf("\n\n2.exit");
printf("\n\n\n enter choice"); scanf("%d",& choice);
printf("%d", choice); if(choice>2)

printf("\n\n invalid option....please renter");


switch(choice)
{
case 1:
charc ();
break;
case 2:
exit(0);
}
}
}
void charc(void)
{
char c[50],d[50],t[50];
int i,m,j;
clrscr();
printf("enter the number of characters\n"); scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
scanf("%c",&c[i]);
}
printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{
if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{
d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}
d[j]=c[i];
}
m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n"); for(i=0;i<m; i ++)
{
printf ("%c",d[i]);
}
for(i=6,j=0;i<m-6;i++,j++)
{
if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'
&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}
printf("\n\n received data:");
for(i=0;i<j; i++)
{printf("%c", t[i]);
}
}
MODEL OUTPUT:

RESULT:

Thus the program for implementation of a data link control for bit stuffing method is executed
and output is verified successfully.

You might also like