department of electronics and communication...

132
CHENNAI - 600062. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING LABORATORY MANUAL COURSE TITLE : COMPUTER NETWORKS LABORATORY COURSE CODE/ REGULATION : EC8563 /R2017 CLASS & SEMESTER : III B.E. ECE & VSEM COURSE TYPE : Core COURSECREDITS : UG Credits: 2 PREREQUISITES : PREPARED BY : Mrs. S. Janaki &Ms. S.H. Annie Silviya Assistant Professor APPROVED BY : Dr.M.Anto Bennet, Professor/HOD

Upload: others

Post on 30-May-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

CHENNAI - 600062.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

LABORATORY MANUAL

COURSE TITLE : COMPUTER NETWORKS LABORATORY

COURSE CODE/ REGULATION : EC8563 /R2017

CLASS & SEMESTER : III B.E. ECE & VSEM

COURSE TYPE : Core

COURSECREDITS : UG Credits: 2

PREREQUISITES :

PREPARED BY : Mrs. S. Janaki &Ms. S.H. Annie Silviya

Assistant Professor

APPROVED BY : Dr.M.Anto Bennet, Professor/HOD

Page 2: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

TABLE OF CONTENTS

S.NO. CONTENTS PAGE NO

1. Institute – Vision & Mission

2. Department – Vision, Mission,

3. Programme Educational Objectives

4. Programme Outcomes- POs

5. Course Outcomes - COs

6. Mapping of POs, PSOs to COs

7. List of Experiment with mapping of POs, PSOs to COs

8. Content Beyond the syllabus – Additional Experiments

9. List of Equipments

10. Procedure for the Experiments

11. Viva Questions

Page 3: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

INSTITUTE VISION &MISSION

Page 4: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

INSTITUTE: VISION

To Develop Globally Competitive Human Resource Through Virtuous Enlightened Learning.

INSTITUTE: MISSION

To Impart Quality Technical Education And Research Orientation Enabling the Technocrats To Fair

Well In Global Competition.

To Inculcate Committed Leadership Qualities Through Ethical Practices.

To Acquire Skills Through Industry Practices And Develop The Habit Of lifelong Learning.

Page 5: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

DEPARTMENTVISION &MISSION

Page 6: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

DEPARTMENT VISION

To Produce Competent and Responsible Engineers to meet the growing Challenges in the field of

Electronics and Communication Engineering.

DEPARTMENT MISSION

M1: To impart strong Technical competency to learners by using best Pedagogical methods.

M2: To provide industrial exposure to leaners by collaboration with Industries for Training, Internship

and Expert Talks.

M3: To imbibe self-learning, collaborative learning, Ethical values and Environmental awareness

through Co-curricular and Extra- curricular activities.

Page 7: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

PROGRAM EDUCATIONAL OBJECTIVES

(PEOs)

Page 8: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

PROGRAM EDUCATIONAL OBJECTIVES (PEOs)

After the successful completion of B.E program

PEO 1: Adapt to dynamically evolving technologies for a successful career in an Academia / Industry /

Entrepreneur.

PEO 2: Apply the Knowledge of Electronics and Communication Engineering to solve real world

problems.

PEO 3: Exhibit Effective Communication skills and can perform as a team player with Leadership Traits.

Page 9: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

PROGRAMME OUTCOMES (POs) /

PROGRAMME SPECIFIC OUTCOMES (PSOs)

Page 10: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

PROGRAM OUTCOMES (POs)

PO 1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering

fundamentals, and an engineering specialization to the solution of complex engineering problems.

PO 2: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.

PO 3: Design/development of solutions: Design solutions for complex engineering problems and

design system components or processes that meet the specified needs with appropriate

consideration for the public health and safety, and the cultural, societal, and environmental

considerations.

PO 4: Conduct investigations of complex problems: Use research-based knowledge and research

methods including design of experiments, analysis and interpretation of data, and synthesis of the

information to provide valid conclusions.

PO 5: 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.

PO 6: 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.

PO 7: 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.

PO 8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms

of the engineering practice.

PO 9: Individual and team work: Function effectively as an individual, and as a member or leader in

diverse teams, and in multidisciplinary settings.

PO10:Communication: Communicate effectively on complex engineering activities with the engineering

community and with society at large, such as, being able to comprehend and write effective

reports and design documentation, make effective presentations, and give and receive clear

instructions.

PO11: Project management and finance: Demonstrate knowledge and understanding of the

engineering and management principles and apply these to one’s own work, as a member and

leader in a team, to manage projects and in multidisciplinary environments.

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 SPECIFIC OUTCOMES (PSOs)

PSO1:Develop Innovative Ideas for an existing / Novel problems through Information and

Communication technologies.

PSO2: Apply the Analog and Digital system Design Principles and practices for Developing Quality

products.

Page 11: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

COURSE OUTCOMES

Page 12: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

Course Outcomes

At the end course Learners should be able to

CO1:To communicate between two desktop computers.

CO2:To implement the different protocols.

CO3:For socket using Java

CO4:To implement and compare the various routing algorithms

CO5: To implement various protocols using NS2

Page 13: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

Mapping of POs, PSOs to COs

Page 14: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

Mapping of POs, PSOs to COs

POs/

PSOs/

Cos

PO1

PO2

PO3

PO4

PO5

PO6

PO7

PO8

PO9

PO10 PO11 PO12 PSO1 PSO2

CO1 3 2 2 2 1 2 2 1 3 3

CO2 3 2 2 1 2 1 2 2 1 3 3

CO3 3 2 2 2 1 2 2 1 3 3

CO4 3 2 2 2 1 2 2 1 3 3

CO5 3 2 2 2 1 2 2 1 3 3

C303 3 2 2 1 2 - - 1 2 2 - 1 3 3

Page 15: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

LIST OF EXPERIMENTS

WITH MAPPING OF

POs/PSOs AND COs

Page 16: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

LIST OF EXPERIMENT

Ex. No.

Name of the Experiment

Hours Relevance to POs &

PSOs

Relevance

to COs

1. Implementation of Error Detection /

Error Correction Techniques

4 PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2

CO1

2. Implementation of Stop and Wait

Protocol and sliding window

4 PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2

CO1

3. Implementation and study of Go back-

N Protocol

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

4. Implementation and study ofselective

repeat protocols

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

5. Implementation of High Level Data

Link Control

4

PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

6.

Write a socket Program for Trace route

commands

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

7.

Write a socket Program for Ping

commands

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

8. Write a socket Program for Nslookup

commands

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

Page 17: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

9. Implementation of IP address

configuration

4

PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

10.

To create scenario and study the

performance of network with CSMA /

CA protocol and compare with

CSMA/CD protocols.

4 PO1,PO2,PO3,PO4,PO5,

PO8,PO9,PO10,PSO1,

PSO2

CO2

11. Network Topology - Star, Bus, Ring

4 PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2

CO3

12. Implementation of distance vector

routing algorithm 4

PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2 CO4

13.

Implementation of Link state routing

algorithm

4

PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2 CO5

14.

Study of Network simulator (NS) and

simulation of Congestion Control

Algorithms using NS

4

PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2 CO5

15. Encryption and decryption. 4

PO1,PO2,PO3,PO5,PO8,

PO9,PO10,PSO1,PSO2 CO4

Total number of Hours 60

Page 18: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

LIST OF EQUIPMENT

Page 19: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

LIST OF EQUIPMENT

SOFTWARE

C / C++ / Java / Equivalent Compiler

Network simulator like NS2/ NS3 / Glomosim/OPNET/ 30 Equivalent

HARDWARE

Standalone desktops 30 Nos

Page 20: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

20

INDEX

S.NO NAME OF THE EXPERIMENTS PAGE NO

1 Implementation of Encryption and Decryption. 21

2 Implementation of error detection/ error correction using hamming code. 25

3 Implementation of Link State Routing. 29

4 Implementation of Distance Vector Routing. 34

5 Write a Socket program for Ping command in java. 39

6 Write a Socket program for trace route command in java. 43

7 Write a socket program for Nslookup command in java. 47

8 Implementation of IP address configuration 50

9 Implementation of Stop and Wait Protocol. 53

10 Implementation of GoBack-N Protocol. 62

11 Implementation of Selective Repeat Protocol. 70

12 Implementation of Sliding window Protocol. 78

13 Implementation of Token Ring Protocol. 83

14 Implementation of Token Bus Protocol. 91

15 Implementation of CSMA/CD. 101

16 Implementation of CSMA/CA. 108

17 Study of high level data link protocol. 117

18 Study of network (NS) and simulation of congestion control algorithm using NS. 108

Content beyond the syllabus

19 RPC 124

20 File Transfer 132

Page 21: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

21

IMPLEMENTATIN AND STUDY OF ENCRYPTION AND DECRYPTION

AIM

To study and implement the process of Encryption and Decryption

APPARATUS REQUIRED:

1. PENTIUM – PC

2. C COMPLIER

3. TURBO C

PRINCIPLE:

CRYPTOGRAPHY (secret writing) is the process which uses the encryption and decryption

algorithm. An encryption algorithm transforms the plain-text into ciphertext (unknown format) and

decryption algorithm transforms the ciphertext back into plain-text. The sender uses an encryption

algorithm to send the information in the unknown format and the receiver uses a decryption algorithm

to retrieve the original information.

ALGORITHM:

CLIENT:

• Start the program

• Initialize the socket for connection establishment

• Write the message

• Convert the message to hexcode format

• Display the message to the server

• Close all objects

• Stop

SERVER:

• Start the program

• Initialize the server socket

Page 22: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

22

• Display waiting for connection

• Display hexcode received from client

• Initialize a new striing builder

• Transform the hexcode into the string format using the string builder

• Display the decrypted message

• Close all objects

• Stop

ENCRYPTION AND DECRYPTION PROGRAM

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<math.h>

#include<string.h>

unsigned long modexp(unsigned long msg,unsigned long exp,unsigned long n)

{

unsigned long i,k=1;

for(i=0;i<exp;i++)

k=(k*msg)%n;

return k;

}

int main()

{

unsigned long p,q,e,d,n,z,i,C,M;

int len;

char data[100];

system("clear");

printf("\nEnter the value of P and Q(such that p*q>255 and p not equal to q)\n");

scanf("%lu%lu",&p,&q);

n=p*q;

z=(p-1)*(q-1);

for(i=1;i<z;i++)

{

if((z%i)==0)

continue;

else

break;

}

e=i;

printf("\nEncryption key is:%lu",e);

Page 23: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

23

for(i=1;i<z;i++)

if(((e*i-1)%z)==0)

break;

d=i;

printf("\nDecryption key is:%lu",d);

printf("\nPls enter the message:");

scanf("%s",data);

len=strlen(data);

for(i=0;i<len;i++)

{

M=(unsigned long)data[i];

C=modexp(M,e,n);

printf("\nEncrypted value its char representation:%lu\t%c\t\n",C,C);

M=modexp(C,d,n);

printf("\nDecrypted value and its char representation:%lu\t%c\t\n",M,M);

}

return 0;

getch();

}

OUTPUT:

RESULT:

Thus the encryption and decryption concept using java is implemented successfully.

Page 24: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

24

VIVA QUESTIONS:

1. What is meant by congestion?

Congestion in a network occurs if user sends data into the network at a rate greater than that allowed

by network resources.

2. Why the congestion occur in a network?

Congestion occurs because the switches in a network have a limited buffer size to store arrived

packets before processing.

3. What is data encryption ?

Data encryption refers to mathematical calculations and algorithmic schemes that transform plaintext

into cyphertext, a form that is non-readable to unauthorized parties. The recipient of an encrypted

message uses a key which triggers the algorithm mechanism to decrypt the data, transforming it to the

original plaintext version.

4. What is RSA algorithm?

An public-key encryption technology developed by RSA Data Security, Inc. The acronym stands for

Rivest, Shamir, and Adelman, the inventors of the technique. The RSA algorithm is based on the fact

that there is no efficient way to factor very large numbers. Deducing an RSA key, therefore, requires

an extraordinary amount of computer processing power and time.The RSA algorithm has become the

de facto standard for industrial-strengthencryption, especially for data sent over the Internet.

5. What is the function of FECN?

The FECN bit is used to warn the receiver of congestion in the network. The sender andreceiver are

communication with each other and are using some type of flow control at a higher level.

Page 25: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

25

ERROR DETECTION USING HAMMING CODE

#include<stdlib.h>

#include<stdio.h>

char data[5];

int encoded[8], edata[7], syndrome[3];

int hmatrix[3][7]={1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,1};

char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};

int main()

{

int i,j;

system("clear");

printf("Hamming Code --- Encoding\n");

printf("Enter 4 bit data:");

scanf("%s",data);

printf("Generator MAtrix\n");

for(i=0;i<4;i++)

printf("\t%s\n",gmatrix[i]);

printf("Encoded Data:");

for(i=0;i<7;i++)

{

for(j=0;j<4;j++)

encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));

encoded[i]=encoded[i]%2;

printf("%d",encoded[i]);

}

printf("\nHamming Code --- Decoding\n");

printf("Enter Encoded bits as received:");

for(i=0;i<7;i++)

scanf("%d",&edata[i]);

for(i=0;i<3;i++)

{

for(j=0;j<7;j++)

syndrome[i]=syndrome[i]+(edata[i]*hmatrix[i][j]);

syndrome[i]=syndrome[i]%2;

}

for(j=0;j<7;j++)

if((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&(syndrome[2]==hmatrix[2][j]))

break;

if(j==7)

printf("Data is error free\n");

else

{

Page 26: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

26

printf("Errorn received at bit number %d of the data\n",j+1);

edata[j]=!edata[j];

printf("The correct data should be:");

for(i=0;i<7;i++)

printf("%d",edata[i]);

}

}#include<stdlib.h>

#include<stdio.h>

char data[5];

int encoded[8], edata[7], syndrome[3];

int hmatrix[3][7]={1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,1};

char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};

int main()

{

int i,j;

system("clear");

printf("Hamming Code --- Encoding\n");

printf("Enter 4 bit data:");

scanf("%s",data);

printf("Generator MAtrix\n");

for(i=0;i<4;i++)

printf("\t%s\n",gmatrix[i]);

printf("Encoded Data:");

for(i=0;i<7;i++)

{

for(j=0;j<4;j++)

encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));

encoded[i]=encoded[i]%2;

printf("%d",encoded[i]);

}

printf("\nHamming Code --- Decoding\n");

printf("Enter Encoded bits as received:");

for(i=0;i<7;i++)

scanf("%d",&edata[i]);

for(i=0;i<3;i++)

{

for(j=0;j<7;j++)

syndrome[i]=syndrome[i]+(edata[i]*hmatrix[i][j]);

syndrome[i]=syndrome[i]%2;

}

for(j=0;j<7;j++)

if((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&(syndrome[2]==hmatrix[2][j]))

break;

if(j==7)

printf("Data is error free\n");

Page 27: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

27

else

{

printf("Errorn received at bit number %d of the data\n",j+1);

edata[j]=!edata[j];

printf("The correct data should be:");

for(i=0;i<7;i++)

printf("%d",edata[i]);

}

}

OUTPUT:

Page 28: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

28

RESULT:

Thus the implementation of error correction and detection using hamming code was successfully

executed.

Page 29: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

29

LINK STATE ROUTING

AIM:

To implement link state routing algorithm.

APPARATUS REQUIRED:

1. PENTIUM – PC

2. C COMPLIER

3. TURBO C

PRINCIPLE:

Link state routing works on the following principle.

* Discover the neighbour and keep their network address.

* Measure the delay or cost to each of its neighbour.

* Construct a packet telling all it has just learned.

* Send the packet to all router.

* Compute the shortest path to every router.

PROCEDURE:

* Open the Cisco Packet Tracer software.

* Add the router and PCs according to our design.

* Configure all the routers and PCs.

* Trace the destination in PC’s command prompt.

* Verify the output.

LINK STATE ROUTING:

#include<stdio.h>

#include<conio.h>

#include<process.h>

#include<string.h>

#include<math.h>

Page 30: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

30

#define IN 99

#define N 6

int dijkstra(int cost[][N],int source,int target);

char

interface[6][6][20]={{"0","0","0","0","0","0"},{"0","0","192.1.1.1","0","200.1.1.1"},{"0","0","0","0",

"198.1.1.2","0"},{"0","192.1.1.3","0","198.1.1.3","0","200.1.1.2"},{"0","0","200.1.1.3","0","200.1.1.4

","0"}};

int main()

{

int cost[N][N],i,j,w,ch,co;

char ip[10];

int source,target,x,y;

printf("\t the shortest path algorithm(DIJKSRTRA'S ALGORITHM in c\n\n");

for(i=1;i<N;i++)

for(j=1;j<N;j++)

cost[i][j]=IN;

for(x=1;x<N;x++)

{

for(y=x+1;y<N;y++)

{

printf("enter the weight of the path between node%d and %d:",x,y);

scanf("%d",&w);

cost[x][y]=cost[y][x]=w;

}

printf("\n");

}

for(x=1;x<N;x++)

{

for(y=1;y<N;y++)

{

printf("%s:\t",interface[x][y]);

//scanf("%s",&ip);

//interface[x][y][20]=ip;

}

printf("\n");

}

printf("\nEnter the source:");

scanf("%d",&source);

printf("\nEnter the target");

scanf("%d",&target);

co=dijsktra(cost,source,target);

printf("\nThe Shortest Path:%d",co);

return 0;

}

int dijsktra(int cost[][N],int source,int target)

Page 31: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

31

{

int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j,x,y;

char path[N];int path1[N];

for(i=0;i<N;i++)

{

dist[i]=IN;

prev[i]=-1;

}

start=source;

selected[start]=1;

dist[start]=0;

while(selected[target]==0)

{

min=IN;

m=0;

for(i=1;i<N;i++)

{

d=dist[start]+cost[start][i];

if(d<dist[i]&&selected[i]==0)

{

dist[i]=d;

prev[i]=start;

}

if(min>dist[i]&&selected[i]==0)

{

min=dist[i];

m=i;

}

}

start=m;

selected[start]=1;

}

start=target;

j=0;

while(start!=-1)

{

path[j++]=start+64;

path1[j++]=start;

start=prev[start];

}

path[j]='\0';

strrev(path);

printf("%s",path);

printf("\n");

for(j=j-1;j>=0;j--)

{

Page 32: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

32

printf("%d\t",path1[j]);

if(j>0)

{

x=path1[j];

y=path1[j-1];

printf("%s\t%s\n",interface[x][y],interface[y][x]);

}

}

return dist[target];

}

OUTPUT:

RESULT:

Thus the link state algorithm was implemented and the output was verified.

Page 33: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

33

VIVA QUESTIONS:

1. What is link state algorithm?

The basic concept of link-state routing is that every node constructs a map of the connectivity to the

network, in the form of a graph, showing which nodes are connected to which other nodes. Each node

then independently calculates the next best logical path from it to every possible destination in the

network. The collection of best paths will then form the node's routing table.

2. List out the services provided by the network layer.

The network layer is responsible for the source-to-destination delivery of a packet possibly across

multiple networks specific responsibility of a network layer includes the following.

a. logical addressing b.Routing.

3. What is a virtual circuit?

A logical circuit made between the sending and receiving computer. The connection is made after both

computers do handshaking. after the connection; all packets follow the same route and arrive in

sequence.

4. What are datagrams?

In datagram approach, each packet is treated independently from all others. Even when one packet

represents just a place of a multipacket transmission, the networks treat if as though it existed alone.

Packets in this technology are referred to as datagrams.

Page 34: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

34

DISTANCE VECTOR ROUTING

AIM:

To implement the distance vector routing algorithm.

APPARATUS REQUIRED:

1. PENTIUM – PC

2. C COMPLIER

3. TURBO C

PRINCIPLE:

It is under dynamic routing algorithm. This algorithm operates by having each route maintains a table

giving the least known distance to reach destination and include line in used to get these. These are

updated by changing information with neighbour. This is called “Bell mann ford algorithm” and “fod

fick” algorithm.

PROCEDURE:

* Open the Cisco Packet Tracer software.

* Add the router and PCs accourding to our design.

* Configure all the routers and PCs.

* Trace the destination in PC’s command prompt.

* Verify the output.

DISTANCE ROUTING ALGORITM:

#include<stdlib.h>

#define nul 1000

#define nodes 10

int no;

struct node

{

int a[nodes][4];

}router[nodes];

void init(int r)

{

int i;

Page 35: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

35

for(i=1;i<=no;i++)

{

router[r].a[i][1]=i;

router[r].a[i][2]=999;

router[r].a[i][3]=nul;

}

router[r].a[r][2]=0;

router[r].a[r][3]=r;

}

void inp(int r)

{

int i;

printf("\nEnter distance from the node %d to other nodes",r);

printf("\nPls Enter 999 of there is no direct route\n",r);

for(i=1;i<=no;i++)

{

if(i!=r)

{

printf("\nEnter dist to node %d:",i);

scanf("%d",&router[r].a[i][2]);

router[r].a[i][3]=i;

}

}

}

void display(int r)

{

int i,j;

printf("\n\nThe routing table for node %d is as follows:",r);

for(i=1;i<=no;i++)

{

if(router[r].a[i][2]>=99)

printf("\n\t\t\t%d\tno link\tno hop",router[r].a[i][1]);

else

printf("\n\t\t\t%d\t\t%d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);

}

}

void dv_algo(int r)

{

int i,j,z;

for(i=0;i<=no;i++)

{

if(router[r].a[i][2]!=999&&router[r].a[i][2]!=0)

{

for(j=1;j<=no;j++)

{

z=router[r].a[i][2]+router[i].a[j][2];

Page 36: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

36

if(router[r].a[j][2]>z)

{

router[r].a[j][2]=z;

router[r].a[j][3]=i;

}

}

}

}

}

int main()

{

int i,j,x,y;

char choice;

printf("Enter the no.of nodes required(less than 10 pls):");

scanf("%d",&no);

for(i=1;i<=no;i++)

{

init(i);

inp(i);

}

printf("\nTne configuration of the nodes after initialization is as follows:");

for(i=1;i<=no;i++)

display(i);

for(i=1;i<=no;i++)

dv_algo(i);

printf("\nThe configuration of the nodes after computation of paths is as follows:");

for(i=1;i<=no;i++)

display(i);

while(1)

{

printf("\n\nWanna continue (y/n):");

scanf("%c",&choice);

if(choice=='n')

break;

printf("\nEnter the nodes btn which the shortest path is to be found:\n");

scanf("%d%d",&x,&y);

printf("\nThe length of the shortest path is %d",router[x].a[y][2]);

}

}

Page 37: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

37

OUTPUT:

RESULT:

Thus the distance vector routing algorithm was implemented and the output was verified.

Page 38: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

38

VIVA QUESTIONS:

1. What is Routing algorithm?

Routing is the process of selecting paths in a network along which to send network traffic. Routing

isperformed for many kinds of networks, including the telephone network (Circuit

switching),electronicdata networks (such as the Internet), and transportation networks.

2.What is Distance vector routing algorithm?

A distance-vector routing protocol is one of the two major classes of routing protocols, the other

majorclass being the link-state protocol. A distance-vector routing protocol requires that a router

informs itsneighbors of topology changes periodically. Compared to link-state protocols, which

require a router toinform all the nodes in a network of topology changes, distance-vector routing

protocols have lesscomputational complexity and message overhead.

3.Define parity bit.

The simplest form of error detection is to append a single bit called a parity bit to a string of data.

4.Define hamming distance.

The number of bits positions in which two codeword differ is called the hamming distance.

5.What is meant by codeword & block length?

Codeword is the encoded block of ‘n’ bits. It contains message bits and redundant bits.

Block length: the number of bits ‘n’ after coding is called the block length of the code

Page 39: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

39

PROGRAM FOR PING

AIM:

To write a socket program for PING in Java.

APPARATUS REQUIRED:

1. PENTIUM – PC

2. Jdk 1.7

3. Java software

ALGORITHM:

1. Start the program.

2. Import Javautil and all necessary packages.

3. Initialize the ping server with socket as null value.

4. Get the IP address of the server using Scanner class.

5. Using get run time () method, executes the specified command in a separate process.

6. Stop the program.

PING program

import java.util.*;

public class PingDemo

{

public void Ping(String host)

{

try

{

Process p=Runtime.getRuntime().exec("Ping "+host);

Scanner scan=new Scanner(p.getInputStream());

while(scan.hasNextLine())

{

System.out.println(scan.nextLine());

}

}

catch(Exception ex)

{

System.out.println("error"+ex);

}

}

public static void main(String args[])

{

PingDemo P1=new PingDemo();

P1.Ping(args[0]);

Page 40: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

40

}

}

OUTPUT:

RESULT:

Thus the socket programming for Ping using Java was written and executed successfully.

Page 41: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

41

VIVA QUESTIONS:

1. What is PING?

2. What is the use of PING?

3. What is a message queue?

4. What are RAW sockets?

5. What are public and private ports?

6. What is a Java bean?

Page 42: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

42

Page 43: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

43

PROGRAM FOR TRACE ROUTE

AIM:

To write a socket program for TRACE ROUTE in Java.

TRACEROUTE Command

1. The trace route command is used to discover the routes that packets actually take when

traveling to their destination. The device (for example, a router or a PC) sends out a

sequence of User Datagram Protocol (UDP) data grams to an invalid port address at the

remote host.

2. Three data grams are sent, each with a Time-To-Live (TTL) field value set to one. The

TTL value of 1 causes the datagram to "timeout" as soon as it hits the first router in the

path; this router then responds with an ICMP Time Exceeded Message (TEM) indicating

that the datagram has expired.

3. Another three UDP messages are now sent, each with the TTL value set to 2, which

causes the second router to return ICMP TEMs. This process continues until the packets

actually reach the other destination.

4. Since these data grams are trying to access an invalid port at the destination host, ICMP

Port Unreachable Messages are returned, indicating an unreachable port; this event

signals the Trace route program that it is finished.

ALGORITHM

Ping Server

1. Start the program.

2. Import 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.

Ping Client

1. Start the program.

2. Import 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.

Page 44: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

44

6. Ping the server.

7. At the receiver end, the server is pinged.

8. Stop the program.

SOURCE CODE

//pingclient.java

import java.io.*;

import java.net.*;

import java.util.Calendar;

class pingclient

{

public static void main(String args[])throws Exception

{

String str;

int c=0;

long t1,t2;

Socket s=new Socket("127.0.0.1",5555);

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

while(c<4)

{

t1=System.currentTimeMillis();

str="Welcome to network programming world";

out.println(str);

System.out.println(dis.readLine());

t2=System.currentTimeMillis();

System.out.println(";TTL="+(t2-t1)+"ms"); c++;

}

s.close();

}

//pingserver.java

import java.io.*;

import java.net.*;

import java.util.*;

import java.text.*;

class pingserver

{

public static void main(String args[])throws Exception

{

ServerSocket ss=new ServerSocket(5555); Socket

s=ss.accept();

int c=0;

Page 45: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

45

while(c<4)

{

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

String str=dis.readLine();

out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length()); c++;

}

s.close();}}

OUTPUT

C:\>javac pingserver.java

Note: pingserver.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

C:\>java pingserver

C:\>javac pingclient.java

Note: pingclient.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

C:\>java pingclient

Reply from welcome-PC/192.168.1.100;Length36; TTL=50ms

Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms

Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms

Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms

RESULT

Thus the socket programming for Trace route using Java was written and executed successfully

Page 46: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

46

VIVA QUESTIONS:

1. What is traceroute?

2. How does the race condition occur?

3. What does a socket consists of?

4. What is the difference between a NULL pointer and a void pointer?

5. What is encapsulation techniques?

Page 47: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

47

NSLOOKUP COMMAND

AIM:

To write a program in java to demonstrate the usage of nslookup command.

ALGORITHM:

1. Import the net, input output packages

2. Use the method exec with the nslookup command and store the result of the command in a

stream

3. Process the stream and print the output

4. End the process

SOURCE CODE:

import java.io.*;

import java.net.*;

class Server

{

public static void main(String args[])

{

try

{

String str;

BufferedReader buf1=new BufferedReader(new

InputStreamReader(System.in));

String ip=buf1.readLine();

Runtime H=Runtime.getRuntime();

Process p=H.exec("nslookup" + ip);

InputStream in=p.getInputStream();

BufferedReader buf2=new BufferedReader(new

InputStreamReader(in));

while((str=buf2.readLine())!=null)

{

System.out.println(" " + str);

}

}

catch(Exception e)

{

Page 48: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

48

System.out.println(e.getMessage());

}

}

}

OUTPUT

C:\>cd C:\Program Files\Java\jdk1.6.0\bin

C:\Program Files\Java\jdk1.6.0\bin>javac server.java

C:\Program Files\Java\jdk1.6.0\bin>java server

C:\Program Files\Java\jdk1.6.0\bin>nslookup

DNS request timed out.

timeout was 2 seconds.

Default Server: UnKnown

Address: 172.15.150.99

> www.google.com

Server: UnKnown

Address: 172.15.150.99

DNS request timed out.

timeout was 2 seconds.

DNS request timed out.

timeout was 2 seconds.

DNS request timed out.

timeout was 2 seconds.

DNS request timed out.

timeout was 2 seconds.

*** Request to UnKnown timed-out

RESULT

Thus the socket programming for Nslookup using Java was written and executed successfully

Page 49: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

49

VIVA QUESTIONS:

1. What is nslookup?

2. What is the use of nslookup?

3. How sockets can be used to write client-server application using a connection-oriented client-

server technique?

4. What this function nslookup does?

5. What this function DNS does?

Page 50: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

50

IMPLEMENTATION OF IP ADDRESS CONFIGURATION

AIM:

To write a program in java to implement IP address configuration..

ALGORITHM:

1. Import the net, input output packages

2. Use the method exec with the ipaddress command and store the result of the command in a

stream

3. Process the stream and print the output

4. End the process

SOURCE CODE:

import java.io.*;

import java.net.*;

class Server

{

public static void main(String args[])

{

try

{

String str;

BufferedReader buf1=new BufferedReader(new

InputStreamReader(System.in));

String ip=buf1.readLine();

Runtime H=Runtime.getRuntime();

Process p=H.exec("ipconfig " + ip);

InputStream in=p.getInputStream();

BufferedReader buf2=new BufferedReader(new

InputStreamReader(in));

while((str=buf2.readLine())!=null)

{

System.out.println(" " + str);

}

}

catch(Exception e)

{

System.out.println(e.getMessage());

}

}

}

Page 51: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

51

OUTPUT:

C:\Program Files\Java\jdk1.6.0\bin>ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection 2:

Connection-specific DNS Suffix . :

Link-local IPv6 Address . . . . . : fe80::40df:b33b:1fa:248e%13

IPv4 Address. . . . . . . . . . . : 172.15.129.34

Subnet Mask . . . . . . . . . . . : 255.255.192.0

Default Gateway . . . . . . . . . : 172.15.165.1

Tunnel adapter isatap.{EF6F8129-49FC-4628-A9A0-3CE89630B9F0}:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Tunnel adapter Local Area Connection* 9:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Tunnel adapter 6TO4 Adapter:

Connection-specific DNS Suffix . :

IPv6 Address. . . . . . . . . . . : 2002:ac0f:8122::ac0f:8122

Default Gateway . . . . . . . . . : 2002:c058:6301::c058:6301

RESULT

Thus the program for IP Address Configurationusing Java was written and executed successfully.

Page 52: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

52

VIVA QUESTIONS:

1. What is IP CONFIG?

2. How to get a valid ipconfig?

3. What is TCP/IP configuration?

4. What are the parameters ipconfig displays?

5. What is the use of DNS and DHCP in ipconfig?

Page 53: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

53

IMPLEMENTATION AND STUDY OF STOP & WAIT PROTOCOL

AIM

To study and implement the “STOP & WAIT” protocol.

APPARATUS REQUIRED:

1. Pentium – PC

2. Eclipse

3. Java

PRINCIPLE:

• Protocols in which the sender sends a frame and then waits for an acknowledgement before

proceeding are called “STOP & WAIT” protocol.

• The data traffic is simple.

• Frames will travel in both the direction.

• The sender in this protocol simply receives a packet from the network layer copies it into a frame,

and then transmit it.

• After transmission, the sender will go to busy waits state until an acknowledgement is received

from the receiver.

• The receiver simply waits in a busy state until a frame is received.

• Once a frame is received it passes the data packet to the network layer and sends an

acknowledgement for the frame it just received.

• It then loops back to busy waiting and the process continues until the End of File is reached.

• In this protocol, there can be only one outgoing frame at a time so no sequence numbers are

required.

• The acknowledgement sent by the receiver to the sender is nothing more than an empty frame.

• Another frame will not be sent until this acknowledgement is received.

Page 54: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

54

ALGORITHM:

SERVER SIDE

1. Initialize server socket

2. Display waiting for connection

3. Initialize the socket and accept the client message

4. Display connected with client

5. Initialize i/p stream

6. Initialize o/p stream

7. Display the message received from client

8. Check the condition

9. Display the message acknowledgement sent to client from client

10. Close all objects

11. Stop

CLIENT SIDE

1. Open socket with input address ,port

2. Display the message server connected

3. Initialize o/p stream

4. Initialize i/p stream

5. Create sub frame

6. Write message

7. Display the message frame sent to server

8. Check the condition

9. Display the message acknowledgement received from server

10. Close all objects

11. Stop

Page 55: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

55

STOP AND WAIT PROGRAM

SERVER

import java.io.*;

import java.net.*;

public class snws

{

public static void main(String args[])

{

try

{

System.out.println("============== SERVER =============");

String frame = null;

String ack = null;

//1. creating a server socket

ServerSocket ss = new ServerSocket(123);

//2. Wait for connection

System.out.println("Waiting for connection");

Socket con = ss.accept();

System.out.println("Connected with client - IP : " + con.getInetAddress().getHostAddress());

//3. set Input and output streams

ObjectInputStream in = new ObjectInputStream(con.getInputStream());

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

//4. receive frame length to control for loop

Page 56: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

56

String framelength= (String)in.readObject();

//5. frame receiving and acknowledgment sending process

int ackno = 0;

for(int i=0;i<Integer.parseInt(framelength);i++)

{

frame = (String)in.readObject();

System.out.println("Frame Received from Client " + frame);

// swap acknowledge number

if(ackno == 0)

ackno = 1;

else

ackno = 0;

// compose acknowledge message

ack = "ack" + ackno;

// send acknowledgment to client

out.writeObject(ack);

System.out.println("Acknowlegement Sent to Client : " + ack);

}

in.close();

out.close();

ss.close();

}

catch(Exception e)

Page 57: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

57

{

System.out.println("Error:" + e);

}

}

}

STOP AND WAIT PROGRAM

CLIENT

import java.io.*;

import java.net.*;

public class snwc

{

public static void main(String args[])

{

try

{

System.out.println("============== CLIENT ==============");

String frame = null;

String ack = null;

//1. creating a socket to connect to the server

Socket con = new Socket("localhost",123);

System.out.println("Connected with server - IP: "+con.getInetAddress().getHostAddress());

//2. set Output and input streams

Page 58: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

58

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

ObjectInputStream in = new ObjectInputStream(con.getInputStream());

frame = "program";

//3. send the frame length to server to control loop operation in server

out.writeObject(Integer.toString(frame.length()));

//4. frame sending and acknowledgment receiving process

String subframe = null;

int frameno = 0;

for(int i=0; i< frame.length();i++)

{

subframe = frame.substring(i,i+1);

out.writeObject("frame" + frameno + " : "+ subframe );

System.out.println("frame" + frameno + " Sent to Server : " + subframe);

if(frameno == 0)

frameno = 1;

else

frameno = 0;

ack = (String)in.readObject();

System.out.println("Ack received from Server : " + ack);

}

//5. Close all objects

in.close();

out.close();

Page 59: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

59

con.close();

}

catch(Exception e)

{

System.out.println("socket error:"+e);

}

}

}

OUTPUT:

CLIENT:

============================= CLIENT ============================

Connected with server - IP: 127.0.0.1

frame0 Sent to Server : p

Ack received from Server : ack1

frame1 Sent to Server : r

Ack received from Server : ack0

frame0 Sent to Server : o

Ack received from Server : ack1

frame1 Sent to Server : g

Ack received from Server : ack0

frame0 Sent to Server : r

Ack received from Server : ack1

frame1 Sent to Server : a

Page 60: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

60

Ack received from Server : ack0

frame0 Sent to Server : m

Ack received from Server : ack1

SERVER:

============================ SERVER =============================

Waiting for connection

Connected with client - IP : 127.0.0.1

Frame Received from Client frame0 : p

Acknowlegement Sent to Client : ack1

Frame Received from Client frame1 : r

Acknowlegement Sent to Client : ack0

Frame Received from Client frame0 : o

Acknowlegement Sent to Client : ack1

Frame Received from Client frame1 : g

Acknowlegement Sent to Client : ack0

Frame Received from Client frame0 : r

Acknowlegement Sent to Client : ack1

Frame Received from Client frame1 : a

Acknowlegement Sent to Client : ack0

Frame Received from Client frame0 : m

Acknowlegement Sent to Client : ack1

RESULT

Thus the “STOP AND WAIT” protocol programmed using java was implemented successfully

Page 61: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

61

VIVA QUESTIONS:

1. What is stop and wait ARQ protocol?

Stop-and-wait ARQ is a method used in telecommunications to send information between two

connected devices. It ensures that information is not lost due to dropped packets and that packets are

received in the correct order. It is the simplest kind of automatic repeat-request (ARQ) method. A

stop-and-wait ARQ sender sends one frame at a time; it is a special case of the general sliding

windowprotocol with both transmit and receive window sizes equal to 1. After sending each frame,

the senderdoesn't send any further frames until it receives an acknowledgement (ACK) signal. After

receiving a good frame, the receiver sends an ACK. If the ACK does not reach the sender before a

certain time,known as the timeout, the sender sends the same frame again.

2. In which layer error detection & error correction find?

Data can be corrupted during transmission. Transmission errors detected at physical layer of OSI

model. Transmission errors corrected at the data link layer.

3. Write the types of error & define it.

There are two types of error

a. single bit error only one bit in the data unit such as a byte, character , or packet changed from 1 to 0

or from 0 to1.

b. burst error :A burst error means that two or more bits in the data unit has changed from 1 to 0 or

0to1.

4. Define data link layer.

Data link layer is the second layer in OSI model. The DLL lies between the network layer & physical

layer. It receives services from physical layer and provides services to the network layer. The DLL

isresponsible for carrying a packet from one hop to next hop.

5. List out the duties of DLL?

Duties of DLL are Packet zing,Addressing,Error control, Flow control, Medium access control

Page 62: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

62

IMPLEMENTATION AND STUDY OF GO-BACK-N PROTOCOL

AIM

To study and implement the “GO-BACK-N” protocol

APPARATUS REQUIRED:

1. Pentium – PC

2. Eclipse

3. Java

PRINCIPLE:

• Go-Back-N ARQ is a automatic repeat request (ARQ) protocol

• In which the sending process continues to send a number of frames specified by awindow size even

without receiving an acknowledgement (ACK) packet from the receiver.

• It is a special case of the general sliding window protocol with the transmit window size

of N and receive window size of 1.

• The receiver process keeps track of the sequence number of the next frame it expects to receive, and

sends that number with every ACK it sends.

• The receiver will discard any frame that does not have the exact sequence number it expects and will

resend an ACK for the last correct in-order frame.

• Once the sender has sent all of the frames in its window, it will detect that all of the frames since the

first lost frame are outstanding, and will go back to the sequence number of the last ACK it received

from the receiver process and fill its window starting with that frame and continue the process over

again.

ALGORITHM

SERVER SIDE

1. Initialize server socket

2. Display waiting for connection

3. Initialize the socket and accept the client message

4. Display connected with client

5. Initialize i/p stream

6. Read message length

Page 63: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

63

7. Display message length

8. Read message from error occurred bit

9. Display message received from error bit

10. Close all objects

11. Stop

CLIENT SIDE:

1. Open socket with input address ,port

2. Display the message server connected

3. Initialize o/p stream

4. Write message

5. assign transmission message and error bit

6. Convert string to character array for bit by bit transmission

7. Write message

8. Display the message Retransmitting message from error bit

9. Check the condition

10. Display the array

11. Close all objects

12. Stop

GO BACK N PROGRAM

SERVER:

import java.io.*;

import java.net.*;

public class gbns

{

public static void main(String[] args)

{

try

{

System.out.println("=============== server ================");

// Initilize socket

Page 64: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

64

ServerSocket ss = new ServerSocket(123);

System.out.println("waiting for connection");

Socket con = ss.accept();

System.out.println("Connected with client - IP: " + con.getInetAddress().getHostAddress());

// Initilize input stream object

ObjectInputStream in = new ObjectInputStream(con.getInputStream());

//Get Message Length

int msgln = Integer.parseInt((String)in.readObject());

//Get Error on

int erroron = Integer.parseInt((String)in.readObject());

// Receiving transmitted message

for(int i=0;i<msgln;i++)

{

System.out.println((String)in.readObject());

}

// Receiving Retransmitting message

System.out.println("Receiving retransmitting message");

for(int i=erroron;i<msgln; i++)

{

System.out.println((String)in.readObject());

}

// close objects

Page 65: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

65

ss.close();

con.close();

in.close();

}

catch (Exception e)

{

System.out.println(“Error: ”+e);

}

}

}

GO BACK N PROGRAM

CLIENT:

import java.io.*;

import java.net.*;

public class gbnc

{

public static void main(String[] args)

{

try

{

System.out.println("=================== client ==============");

// Initilize socket

Page 66: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

66

Socket con = new Socket("localhost",123);

System.out.println("Connected with server - IP: " + con.getInetAddress().getHostAddress());

// Initilize Output stream object

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

String message = "Networks";

int erroron = 2;

// send message length

out.writeObject(Integer.toString(message.length()));

// send error occured place number

out.writeObject(Integer.toString(erroron));

// Starting transmission

for(int i=0;i<message.length();i++)

{

out.writeObject(message.substring(i,i+1));

System.out.println(message.substring(i,i+1));

}

// Starting Retransmission from error occurred place

System.out.println("Retransmitting message from error bit");

for(int i=erroron;i<message.length(); i++)

{

out.writeObject(message.substring(i,i+1));

System.out.println(message.subSequence(i, i+1));

}

Page 67: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

67

// Close objects

con.close();

out.close();

}

catch (Exception e)

{

System.out.println(e);

}

}

}

OUTPUT

============================== client ==========================

Connected with server - IP: 127.0.0.1

N

e

t

w

o

r

k

s

Retransmitting message from error bit

t

w

Page 68: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

68

o

r

k

s

============================== server ==========================

waiting for connection

Connected with client - IP: 127.0.0.1

N

e

t

w

o

r

k

s

Receiving retransmitting message

t

w

o

r

k

s

RESULT

Thus the GO-BACK-N protocol programmed using java is implemented successfully.

Page 69: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

69

VIVA QUESTIONS:

1. What is Go Back – N Protocol?

2. Give the features of Go Back – N Protocol.

3. What are the advantages and disadvantages of Go Back – N Protocol?

4. What is a window size in Go Back – N Protocol?

5. At which layer Go Back – N Protocol is implemented?

Page 70: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

70

IMPLEMENTATION AND STUDY OF SELECTIVE REPEAT PROTOCOL

AIM

To study and implement the “SELECTIVE REPEAT” protocol.

APPARATUS REQUIRED:

1. Pentium – PC

2. Eclipse

3. Java

PRINCIPLE:

• Only damage or lost frame is retransmitted.

• If the frame is corrupted in transmit and NO ACK is retained and the frame is reset outof the

sequence.

• The receiving device must be able to sort the frames it has and insert the retransmitted frames into its

proper place in the sequence.

ALGORITHM:

SERVER SIDE:

1. Initialize server socket

2. Display waiting for connection

3. Initialize the socket and accept the client message

4. Display connected with client

5. Initialize i/p stream

6. Read message length

7. Display message length

8. Read message from error occurred bit

9. Display message received from error bit

10. Close all objects

11. Stop

Page 71: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

71

CLIENT SIDE:

1. Open socket with input address ,port

2. Display the message server connected

3. Initialize o/p stream

4. Write message

5. assign transmission message and error bit

6. Convert string to character array for bit by bit transmission

7. Write message

8. Display the message Retransmitting message from error bit

9. Check the condition

10. Display the array

11. Close all objects

12. Stop

SERVER:

import java.io.*;

import java.net.*;

public class srs

{

public static void main(String[] args)

{

try

{

System.out.println("================ server ================");

// Initilize socket

ServerSocket ss = new ServerSocket(123);

System.out.println("waiting for connection");

Page 72: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

72

Socket con = ss.accept();

System.out.println("Connected with client - IP: " + con.getInetAddress().getHostAddress());

// Initilize input stream object

ObjectInputStream in = new ObjectInputStream(con.getInputStream());

//Get Message Length

int msgln = Integer.parseInt((String)in.readObject());

//Get Error on

int erroron = Integer.parseInt((String)in.readObject());

// Receiving trasmitted message

for(int i=0;i<msgln;i++)

{

System.out.println((String)in.readObject());

}

// Starting Retransmission from error occurred place

System.out.println("Receiving retransmitting message");

System.out.println((String)in.readObject());

// close objects

ss.close();

con.close();

in.close();

}

catch (Exception e)

Page 73: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

73

{

System.out.println(“Error : ”+e);

}

}

}

CLIENT

import java.io.*;

import java.net.*;

public class src

{

public static void main(String[] args)

{

try

{

System.out.println("============================== client ===================");

// Initilize socket

Socket con = new Socket("localhost",123);

System.out.println("Connected with server - IP: " + con.getInetAddress().getHostAddress());

// Initilize Output stream object

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

String message = "Networks";

int erroron = 3;

// send message length

Page 74: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

74

out.writeObject(Integer.toString(message.length()));

// send error occured place number

out.writeObject(Integer.toString(erroron));

// Starting actual transmission

for(int i=0;i<message.length();i++)

{

out.writeObject(message.substring(i,i+1));

System.out.println(message.substring(i,i+1));

}

// Retransmitting error occured character

System.out.println("Retransmitting error occured character");

out.writeObject(message.substring(erroron,erroron+1));

System.out.println(message.subSequence(erroron, erroron+1));

// Close objects

con.close();

out.close();

}

catch (Exception e)

{

System.out.println(e);

}

}

Page 75: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

75

OUTPUT

============================== client ==========================

Connected with server - IP: 127.0.0.1

N

e

t

w

o

r

k

s

Retransmitting error occured character

w

============================== server ==========================

waiting for connection

Connected with client - IP: 127.0.0.1

Page 76: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

76

N

e

t

w

o

r

k

s

Receiving retransmitting message

w

RESULT:

Thus the “SELECTIVE REPEAT” protocol programmed using java is implemented

successfully.

Page 77: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

77

VIVA QUESTIONS:

1. What is selective reject ARQ protocol..

Selective Repeat ARQ / Selective Reject ARQ is a specific instance of the Automatic Repeat-Request

(ARQ) protocol used for communications. It may be used as a protocol for the delivery and

acknowledgement of message units, or it may be used as a protocol for the delivery of subdivided

message sub-units.

2. What is Go back N ARQ protocol?

Go-Back-N ARQ is a specific instance of the automatic repeat request (ARQ) protocol, in which the

sending process continues to send a number of frames specified by a window size even without

receiving an acknowledgement (ACK) packet from the receiver. It is a special case of the general

sliding window protocol with the transmit window size of N and receive window size of 1.

3.Define parity bit.

The simplest form of error detection is to append a single bit called a parity bit to a string of data.

4.Define hamming distance.

The number of bits positions in which two codeword differ is called the hamming distance.

5.What is meant by codeword & block length?

Codeword is the encoded block of ‘n’ bits. It contains message bits and redundant bits.

Block length: the number of bits ‘n’ after coding is called the block length of the code.

Page 78: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

78

IMPLEMENTATION OF SLIDING WINDOW PROTOCOL

AIM:

To write a java program to perform sliding window.

ALGORITHM:

1. Start theprogram.

2. Get the frame size from theuser

3. To create the frame based on the user request. 4.To

send frames to server from the clientside.

5. If your frames reach the server it will send ACK signal to client otherwise itwill

send NACK signal toclient.

6. Stop theprogram

Sender:

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;

Page 79: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

79

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;

}

Page 80: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

80

System.out.print("\nDo you wants to send some more frames : ");

ch=in.readLine(); p.println(ch);

}

while(ch.equals("yes"));

s.close();

}

}

Receiver:

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)

{

Page 81: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

81

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"));

}

}

Page 82: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

82

Output:

RESULT:

Thus the “Sliding window” protocol programmed using java is implemented successfully.

Page 83: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

83

TOKEN RING PROTOCOL

AIM:

To study and implement the token ring protocol.

APPARATUS REQUIRED:

• Pentium pc

• Java and eclipse software

PRINCIPLE:

• In the token passing method, the stations in a network are organized In a logical ring.

• In a physical ring topology, when a station sends the token to its successor, the token

cannot be seen by other stations.

• In this, each device has a dedicated point-to-point connection with only the two devices

on either side of it.

• In this method, a special packet called token circulates throughout the ring.

• When a station has some data to send, it waits until it receives the token from its

predecessor. It then holds the token and sends its data.

• When the station has no more data to send, it releases the token, passing it to the next

logical station in the ring

ALGORITHM:

Client 1:

• Start the program

• Open socket with input address and port

• Establish a connection between client 1 and client2

• Pass the token to client 2

Page 84: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

84

• Stop the program

Client 2:

• Start

• Initialize server server socket

• Wait to connect with client2

• Initialize the socket and accept the client message

• Display connected with client1

• Receive the token sent by client 1

• Establish a connection between client 2 and client 3

• Open socket with input address and port

• Pass the token to client 3

• Stop

Client 3:

• Start

• Initialize server socket

• Wait to connect with client2

• Initialize the socket and accept the client2 mess

• Receive the token which has sent by client2

TOKEN RING PROGRAM

CLIENT 1

import java.io.IOException;

import java.net.Socket;

import java.net.SocketException;

public class cl1

{

Page 85: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

85

public static void main (String args [])

{

try

{

System.out.println("========== Client 1 =========");

Socket con = new Socket("192.168.5.2",140);

System.out.print("Token Sent to Client 2 : "+ con.getInetAddress().getHostAddress());

con.close();

}

catch (SocketException e)

{

System.out.print("\n Clinet 2 is disconnected from LAN");

System.out.print("\n Token Ring breaks");

}

catch(IOException e)

{

System.out.println("io error:"+e);

}

}

}

TOKEN RING PROGRAM

CLIENT 2

import java.io.IOException;

Page 86: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

86

import java.net.ServerSocket;

import java.net.Socket;

public class cl2

{

public static void main (String args [])

{

try

{

System.out.println("========== Client 2 =========");

ServerSocket providersocket = new ServerSocket(140);

System.out.println("waiting for connection");

Socket con = providersocket.accept();

System.out.print("Token received from Client 1 : "+ con.getInetAddress().getHostAddress());

providersocket.close();

Thread.sleep(4000);

try

{

System.out.println(" \n==== Passing Token to next client ======");

Socket con2 = new Socket("192.168.5.3",140);

System.out.print("Token sent to Client 3 :"+ con2.getInetAddress().getHostAddress());

con2.close();

}

catch(IOException e)

Page 87: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

87

{

System.out.println("Client 3 is disconnected from LAN");

System.out.println("\n Token Ring breaks");

}

}

catch (IOException e)

{

System.out.println("socket error:" +e);

}

catch (InterruptedException e)

{

System.out.println("socket error:" +e);

}

}

}

TOKEN RING PROGRAM

CLIENT 3

import java.io.IOException;

import java.net.ServerSocket;

import java.net.Socket;

public class cl3

{

public static void main (String args [])

Page 88: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

88

{

try

{

System.out.println("========== Client 3 =========");

ServerSocket providersocket = new ServerSocket(140);

System.out.println("waiting for connection");

Socket con = providersocket.accept();

System.out.print("Token received from Client 2 : "+ con.getInetAddress().getHostAddress());

providersocket.close();

}

catch (IOException e)

{

System.out.println("socket error:" +e);

}

}

}

Case 1 : When all the clients connected in LAN

Client 1:

========== Client 1 =========

Token Sent to Client 2 : 192.168.5.2

Client 2:

========== Client 2 =========

waiting for connection

Token received from Client 1 : 192.168.5.1

Page 89: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

89

========== Passing Token to next client =========

Token sent to Client 3 :192.168.5.3

Client 3 :

========== Client 3 =========

waiting for connection

Token received from Client 2 : 192.168.5.2

Case 2: When Client 2 disconnected from LAN

Client 1:

========== Client 1 =========

Client 2 is disconnected from LAN

Token Ring breaks

Client 2:

(Don’t run program in client2, it is assumed like client 2 disconnected from LAN)

Client 3:

========== Client 3 =========

waiting for connection

Case 3: When Client 3 disconnected from LAN

Client 1:

========== Client 1 =========

Token Sent to Client 2 : 192.168.5.2

Client 2:

========== Client 2 =========

waiting for connection

Token received from Client 1 : 192.168.5.1

========== Passing Token to next client =========

Page 90: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

90

Client 3 is disconnected from LAN

Token Ring breaks

Client 3:

(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)

Case 4: When Client 2 and Client 3 disconnected from LAN

Client 1:

========== Client 1 =========

Client 2 is disconnected from LAN

Client 2:

(Don’t run program in client 2 it is assumed like client 2 disconnected from LAN)

Client 3:

(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)

PROCEDURE:

1. Type the Client 1, Client 2 and Client 3 program in three different computers.

2. To verify Case 1: first execute Client 3 then Client 2 then Client 1, so Client 3waiting for token

from Client 2, Client 2 waiting for Token from Client 1, Client 1 starts the token sending, it sends

token to Client 2, now client 2 holds token for 40 seconds then it sends token to Client 3.

3. To verify Case 2: first execute Client 3 then Client 1, don’t execute program in Client 2 (It is

assumed like Client 2 is disconnected from the LAN), Client 1 starts the token sending, it sends token

to Client 2, but Client 2 is disconnected from the LAN, so that, the token ring breaks.

4. To verify Case 3: Don’t execute Client 3 (It is assumed like Client 3 is disconnected from LAN),

execute program in Client 2 then Client 1, Client 1 sends token to Client 2, now Client 2 trying to send

token to Client 3, but Client 3 is disconnected from the LAN, so that, token ring breaks.

5. To verify Case 4 : Don’t execute Client 3 and Client 2 (It is assumed like Client 3 and Client 2 are

disconnected from the LAN). So the token ring process is not initiated at all.

RESULT: Thus, the token ring protocol was programmed using java and implemented successfully in

the laboratory.

Page 91: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

91

TOKEN BUS PROTOCOL

AIM:

To study and implement the token bus protocol.

APPARATUS REQUIRED:

• Pentium pc

• Java and eclipse software

PRINCIPLE:

• In this, one long cable acts as a backbone to link all the devices in a network. If the backbone is

broken, the entire segment fails.

• When a station has finished sending its data, it releases the token and inserts the address of its

successor in the token.

• Only the station with address matching the destination address of the token gets thetoken to access

the shared media.

• In the intermediate system fails, the token directly passes to the next available system.But it’s not

applicable in token ring protocol.

ALGORITHM:

CLIENT1:

1. Start the program

2. Open socket with input address and port

3. Establish a connection between client 1 , client2 and client3

4. Pass the token to client 2

5. If the client 2 breaks, pass token to client3

6. Stop the program

Page 92: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

92

CLIENT 2:

1. Start

2. Initialize server server socket

3. Wait to connect with client2

4. Initialize the socket and accept the client1 message

5. Displaly connected with client1

6. Receive the token sent by client 1

7. Establish a connection between client 2 and client 3

8. Open socket with input address and port

9. Pass the token to client 3

10. If the client 3 is disconnected,terminate the program

11. Stop

CLIENT 3:

1. Start

2. Initialize server socket

3. Wait to connect with client2

4. Initialize the socket and accept the client2 mess

5. Receive the token which has sent by client2

6. If the client 2 is disconnected, receive the token by client 1.

7. stop

TOKEN BUS PROGRAM

CLIENT 1

import java.io.IOException;

import java.net.Socket;

import java.net.SocketException;

Page 93: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

93

public class cl1

{

public static void main (String args [])

{

try

{

System.out.println("========== Client 1 =========");

Socket con = new Socket("192.168.5.2",140);

System.out.print("Token Sent to Client 2 : "+ con.getInetAddress().getHostAddress());

con.close();

}

catch (SocketException e)

{

try

{

System.out.print("Clinet 2 is disconnected from LAN");

Socket con2 = new Socket("192.168.5.3",140);

System.out.print("\n Token Sent to Client 3 : "+ con2.getInetAddress().getHostAddress());

con2.close();

}

catch(IOException e2)

{

System.out.print("\n Clinet 3 is disconnected from LAN");

Page 94: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

94

}

}

catch(IOException e)

{

System.out.println("io error:"+e);

}

}

}

TOKEN BUS PROGRAM

CLIENT 2

import java.io.IOException;

import java.net.ServerSocket;

import java.net.Socket;

public class cl2

{

public static void main (String args [])

{

try

{

System.out.println("========== Client 2 =========");

ServerSocket providersocket = new ServerSocket(140);

System.out.println("waiting for connection");

Page 95: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

95

Socket con = providersocket.accept();

System.out.print("Token received from Client 1 : "+ con.getInetAddress().getHostAddress());

providersocket.close();

Thread.sleep(4000);

try

{

System.out.println(" \n==== Passing Token to next client ====");

Socket con2 = new Socket("192.168.5.3",140);

System.out.print("Token sent to Client 3 :"+ con2.getInetAddress().getHostAddress());

con2.close();

}

catch(IOException e)

{

System.out.println("Client 3 is disconnected from LAN");

}

}

catch (IOException e)

{

System.out.println("socket error:" +e);

}

catch (InterruptedException e)

{

System.out.println("socket error:" +e);

Page 96: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

96

}

}

}

TOKEN BUS PROGRAM

CLIENT 3

import java.io.IOException;

import java.net.ServerSocket;

import java.net.Socket;

public class cl3

{

public static void main (String args [])

{

try

{

System.out.println("========== Client 3 =========");

ServerSocket providersocket = new ServerSocket(140);

System.out.println("waiting for connection");

Socket con = providersocket.accept();

System.out.print("Token received from Client 2 : "+ con.getInetAddress().getHostAddress());

providersocket.close();

}

catch (IOException e)

{

Page 97: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

97

System.out.println("socket error:" +e);

}

}

}

Case 1 : When all the clients connected in LAN

Client 1:

========== Client 1 =========

Token Sent to Client 2 : 192.168.5.2

Client 2:

========== Client 2 =========

waiting for connection

Token received from Client 1 : 192.168.5.1

========== Passing Token to next client =========

Token sent to Client 3 :192.168.5.3

Client 3 :

========== Client 3 =========

waiting for connection

Token received from Client 2 : 192.168.5.2

Case 2: When Client 2 disconnected from LAN

Client 1:

========== Client 1 =========

Clinet 2 is disconnected from LAN

Token Sent to Client 3 : 192.168.5.3

Client 2:

(Don’t run program in client2, it is assumed like client 2 disconnected from LAN)

Page 98: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

98

Client 3:

========== Client 3 =========

waiting for connection

Token received from Client 1 : 192.168.5.1

Case 3: When Client 3 disconnected from LAN

Client 1:

========== Client 1 =========

Token Sent to Client 2 : 192.168.5.2

Client 2:

========== Client 2 =========

waiting for connection

Token received from Client 1 : 192.168.5.1

========== Passing Token to next client =========

Client 3 is disconnected from LAN

Client 3:

(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)

Case 4: When Client 2 and Client 3 disconnected from LAN

Client 1:

========== Client 1 =========

Clinet 2 is disconnected from LAN

Clinet 3 is disconnected from LAN

Client 2:

(Don’t run program in client 2 it is assumed like client 2 disconnected from LAN)

Client 3:

(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)

Page 99: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

99

PROCEDURE:

1. Type the Client 1, Client 2 and Client 3 program in three different computers.

2. To verify Case 1: first execute Client 3 then Client 2 then Client 1, so Client 3 waiting for token

from Client 2, Client 2 waiting for Token from Client 1, Client 1 starts the token sending, it sends

token to Client 2, now client 2 holds token for 40 seconds then it sends token to Client 3.

3. To verify Case 2: first execute Client 3 then Client 1, don’t execute program in Client 2 (It is

assumed like Client 2 is disconnected from the LAN), Client 1 starts the token sending, it sends token

to Client 2, but Client 2 is disconnected from the LAN, so the token sent to Client 3.

4. To verify Case 3: Don’t execute Client 3 (It is assumed like Client 3 is disconnected from LAN),

execute program in Client 2 then Client 1, Client 1 sends token to Client 2, now Client 2 trying to send

token to Client 3, but Client 3 is disconnected from the LAN, so token not sent to Client 3.

5. To verify Case 4 : Don’t execute Client 3 and Client 2 (It is assumed like Client 3 and Client 2 are

disconnected from the LAN)

RESULT:

Thus, the token bus protocol was programmed using java and implemented successfully.

Page 100: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

100

VIVA QUESTIONS:

1. What is token ring?

Token ring local area network (LAN) technology is a local area network protocol which resides at the

data link layer (DLL) of the OSI model. It uses a special three-byte frame called a token that travels

around the ring. Token-possession grants the possessor permission to transmit on the medium. Token

ring frames travel completely around the loop.

2.What is token bus?

Token bus is a network implementing the token ring protocol over a "virtual ring" on a coaxial cable.

A token is passed around the network nodes and only the node possessing the token may transmit. If a

node doesn't have anything to send, the token is passed on to the next node on the virtual ring. Each

node must know the address of its neighbour in the ring, so a special protocol is needed to notify the

other nodes of connections to, and disconnections from, the ring.

3.Define networks.

A network is a set of devices connected by media links.

4. Define Communication channels

The links connecting the devices are often called communication channel.

5.What is meant by distributed processing & write any two advantages.

Networks use distributed processing in which a task is divided among multiple computers.

Advantages: Security, Faster problem sloving, Collaborative processing

Page 101: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

101

IMPLEMENTATION AND STUDY OF CSMA/CD

AIM

To study and implement the Carrier Sense Multiple Access with Collision Detection

APPARATUS REQUIRED:

1. Pentium – PC

2. Eclipse

3. Java

PRINCIPLE:

The Carrier Sense Multiple Access is based on the principle of “SENSE BEFORETRANSMIT”. This

CSMA/CD is generally used in wired networks. It is mainly focused to detect the collision if it has

occurred.

ALGORITHM:

SERVER:

1. Initialize server socket

2. Display waiting for connection

3. Initialize the socket and accept the client message

4. Display connected with client

5. Initialize i/p stream

6. Read message

7. Display message from client

8. Close all objects

9. Stop

CLIENT:

Page 102: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

102

1. Open socket with input address ,port

2. Initialize o/p stream

3. Send the message, if message sent collision not occurred.

4. If message not sent, collision occurred (To occur collision don’t run not server)

5. Calculate back of time using random number selection and wait for that time

6. Again send the message, if message sent collision not occurred.

7. If message not sent, collision occurred, Again calculate back off time by selecting random number,

this trail can be done for 15 times.

8. If not succeeded with 15 trails transmission will be stopped.

CSMA/CD PROGRAM

SERVER:

import java.io.*;

import java.net.*;

public class Server

{

public static void main(String[] args)

{

try

{

System.out.println("============ Client 2 ===============");

ServerSocket ss = new ServerSocket(137);

System.out.println("Waiting for connection");

Socket con = ss.accept();

System.out.println("Connected");

Page 103: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

103

ObjectInputStream in = new ObjectInputStream(con.getInputStream());

System.out.println((String)in.readObject());

in.close();

ss.close();

}

catch(Exception e)

{

System.out.println(e);

}

}

}

CSMA/CD PROGRAM

CLEINT:

import java.io.*;

import java.net.*;

public class client1

{

public static void main(String[] args)

{

try

{

System.out.println("============ Client 1 ===============");

client1 cli = new client1();

Page 104: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

104

int Tp = 2000;

int R = 0;

int Tb = 0;

for(int i=1; i<=15;i++)

{

System.out.println("attempt : "+i);

if(cli.send() == "sent")

{

break;

}

else

{

R = 2^i-1;

System.out.println("Selected Random number :"+R);

Tb = R*Tp;

System.out.println("waiting for next attempt with back time (in seconds): "+Tb);

Thread.sleep(Tb);

}

}

}

catch (InterruptedException e)

{

System.out.println(e);

Page 105: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

105

}

}

String send()

{

String str=null;

try

{

Socket soc = new Socket("localhost",137);

ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());

String msg = "CNLAB";

out.writeObject(msg);

System.out.println("Message sent : "+msg);

str = "sent";

}

catch(Exception e)

{

str = "collision occured";

System.out.println("Message sent : "+msg);

}

return str;

}

}

OUTPUT

============ Client 1 ===============

Page 106: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

106

attempt : 1

collision occured

Selected Random number :2

waiting for next attempt with back time (in seconds): 4000

attempt : 2

collision occured

Selected Random number :3

waiting for next attempt with back time (in seconds): 6000

attempt : 3

collision occured

Selected Random number :0

waiting for next attempt with back time (in seconds): 0

attempt : 4

collision occured

Selected Random number :1

waiting for next attempt with back time (in seconds): 2000

attempt : 5

Message sent : CNLAB

============ Server ===============

Waiting for connection

Connected

CNLAB

PROCEDURE:

Page 107: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

107

1. Run the Client program, don’t run server program (consider as to raise collision)

2. Client will try to send the message to server, but server is not running, so the attempt is

failed, so consider as collision occurred.

3. Client will select random number and calculate Back off time and wait for the back off time

and again will try to send the message. This loop continues till the 15 trails.

4. Run the server in between consider as no collision, so message will be sent from client to

server.

RESULT:

Thus the CSMA/CD is executed and studied.

Page 108: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

108

IMPLEMENTATION AND STUDY OF CSMA/CA

AIM

To study and implement the Carrier Sense Multiple Access with collision avoidance.

APPARATUS REQUIRED:

1. Pentium – PC

2. Eclipse

3. Java

PRINCIPLE:

Carrier sense multiple access with collision avoidance (CSMA/CA) is a method in which carrier

sensing is used, nodes attempt to avoid collisions by transmitting only when the channel is sensed to

be "idle"

ALGORITHM

1. Start

2. Initialize k+0

3. Check for the channel idleness

4. If the channel is busy, wait for IFS (InterFrame Space) time

5. Again check for the channel idleness

6. If the channel is busy, keep on checking channel idleness

7. If the channel is idle, choose a random number.

8. Wait for R slots

9. Send frame now

10. Set wait time for receiving acknowledgment

11. If the acknowledgement is received, then the transmission will be completed

12. Else, go for checking the channel idleness

Page 109: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

109

13. Stop

CSMA/CA PROGRAM

CLIENT 1

import java.io.*;

import java.net.*;

public class client

{

public static void main(String[] args)

{

try

{

System.out.println("============ Client 1 ===============");

client cli = new client();

int R = 0;

Boolean bln = false;

for(int k=1; k<=15;k++)

{

System.out.println("attempt : "+k);

// is idle channel?

System.out.println("is Channel idle? ");

Page 110: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

110

int i = 0;

while(true)

{

System.out.print(i=i+1);

if(cli.isidle())

{

System.out.println("\n Channel idle");

System.out.println("Wait IFS time 5000");

// wait for IFS time

Thread.sleep(8000);

// is still idle channel?

System.out.println("is still idle?");

if(cli.isidle())

{

System.out.println("Still idle");

// Choose random number

R = 2^k-1;

System.out.println("Selected Random number :"+R);

System.out.println("waiting for R slot time: "+R*6000);

// wait R slot

Page 111: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

111

Thread.sleep(R*6000);

// send frame

System.out.println("Message sent");

// Timer runs and wait for time out

System.out.println("Wait for time out : "+10000);

Thread.sleep(10000);

// ack check

if(cli.isidle())

{

System.out.println("Ack received");

bln = true;

break;

}

else

{

System.out.println("Ack not received");

break;

}

}

else

{

Page 112: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

112

System.out.println("Busy, goes to channel idle check");

}

}

}

if(bln == true)

{

break;

}

}

}

catch (InterruptedException e)

{

System.out.println(e);

}

}

Boolean isidle()

{

try

{

Socket soc= new Socket("localhost",137);

Page 113: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

113

soc.close();

return true;

}

catch (Exception e)

{

return false;

}

}

}

CLIENT 2

import java.io.*;

import java.net.*;

public class server

{

public static void main(String[] args)

{

try

{

System.out.println("============ Client 2 ===============");

while(true)

Page 114: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

114

{

ServerSocket ss = new ServerSocket(137);

System.out.println("Waiting for connection");

ss.accept();

ss.close();

System.out.println("Connected");

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

OUTPUT:

Case 1: don’t run client 2 (Channel Busy always)

============ Client 1 ==============

attempt : 1

is Channel idle?

123456789101112131415161718192021222324

Case 2: stop client2 on “is still idle” (Channel busy after IFS time)

============ Client 1 ==============

Page 115: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

115

attempt : 1

is Channel idle?

1

Channel idle

Wait IFS time 5000

is still idle?

Busy, goes to channel idle check

2345678910

Case 3: stop client2 on Ack received check (Collision occured)

============ Client 1 ==============

attempt : 1

is Channel idle?

1

Channel idle

Wait IFS time 5000

is still idle?

Still idle

Selected Random number :2

waiting for R slot time: 12000

Message sent

Wait for time out : 10000

Ack not received

attempt : 2

is Channel idle?

Case 4: CSMA/CA ack received

Page 116: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

116

============ Client 1 ===============

attempt : 1

is Channel idle?

1

Channel idle

Wait IFS time 5000

is still idle?

Still idle

Selected Random number :2

waiting for R slot time: 12000

Message sent

Wait for time out : 10000

Ack received

RESULT:

Thus the CSMA/CA is implemented and studied successfully.

Page 117: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

117

STUDY OF HIGH LEVEL DATA LINK PROTOCOL

Aim:

To study about (HDLC) High Level Data Link Protocol

Introduction:

HDLC - Short for High-level Data Link Control, a transmission protocol used at the data link

layer (layer 2) of the OSI seven layer model for data communications. The HDLC protocol embeds

information in a data frame that allows devices to control data flow and correct errors. HDLC is an

ISO standard developed from the Synchronous Data Link Control (SDLC) standard proposed by IBM

in the 1970's. HDLC NRM (also known as SDLC) .HDLC is a bit oriented protocol that supports both

half-duplex and full-duplex communication over point to point & multipoint link.

For any HDLC communications session, one station is designated primary and the other secondary. A

session can use one of the following connection modes, which determine how the primary and

secondary stations interact

• Normal unbalanced: The secondary station responds only to the primary station.

• Asynchronous: The secondary station can initiate a message.

• Asynchronous balanced: Both stations send and receive over its part of a duplex line.

This mode is used for X.25 packet-switching networks.

The Link Access Procedure-Balanced (LAP-B) and Link Access Procedure D-channel (LAP-

D) protocols are subsets of HDLC.

LAPB is a bit-oriented synchronous protocol that provides complete data transparency in a full-duplex

point-to-point operation. It supports a peer-to-peer link in that neither end of the link plays the role of

the permanent master station. HDLC NRM, on the other hand, has a permanent primary station with

one or more secondary stations.

The concept of a frame window is used to send multiple frames before receiving confirmation

that the first frame has been correctly been received. This means that data can continue to flow in

situations where there may be long "turn-around" time lagswithout stopping to wait for an

acknowledgement. This kind of situation occurs, for instance in satellite communication.

HDLC defines three types of frames:

1. Information frames (I-frame)

Page 118: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

118

2. Supervisory frame (S-frame)

3. Unnumbered frame (U-frame)

1. Information frames

• I-frames carry user's data and control information about user's data.

• I-frame carries user data in the information field.

C:\images\Information-frames.jpg• The first bit of control field is always zero, i.e. the presence of

zero at this place indicates that it is I-frame.

• Bit number 2, 3 & 4 in control field is called N(S) that specifies the sequence number of the frame.

Thus it specifies the number of the frame that is currently being sent. Since it is a 3.bit field, only eight

sequence numbers are possible 0, 1,2,3,4,5,6, 7 (000 to 111).

• Bit number 5 in control field is P/F i.e. Poll/Final and is used for these two purposes. It has, meaning

only when it is set i.e. when P/F=1.

It can represent the following two cases.

(i) It means poll when frame is sent by a primary station to secondary (when address field contains the

address of receiver).

(ii) It means final when frame is sent by secondary to a primary (when the address field contains the

address of the sender).

• Bit number 6, 7, and 8 in control field specifies N(R) i.e. the sequence number of the frame expected

in return in two-way communication.

2. Supervisory frame

• S-frame carries control information, primarily data link layer flow and error controls.

C:\images\Supervisory-frame.jpg•The first two bits in the control field of S-frame are always 10.

C:\images\Types-of-S-Frame.jpg1. RR, Receive Ready-used to acknowledge frames when no I-frames

are availab1e to piggyback the acknowledgement.

2. REJ Reject-used by the receiver to send a NAK when error has occurred.

3. RNR Receive Not Ready-used for flow control.

4. SREJ Selective Reject-indicates to the transmitter that it should retransmit the frame

indicated in the N(R) subfield.

• There is no N(S) field in control field of S-frame as S-frames do not transmit data.

Page 119: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

119

• Last three bits in control field indicates N(R) i.e. they correspond to the ACK or NAK value.

3. Unnumbered frame

• U-frames are reserved for system management and information carried by them is used for managing

the link

• U-frames are used to exchange session management and control information between the two

connected devices.

• Information field in U-frame does not carry user information rather, it carries system management

information.

• The frame format of U-frame is shown in diagram.

• U-frame is identified by the presence of 11 in the first and second bit position in control field.

• These frames do not contain N(S) or N(R) in control field.

C:\images\Unnumbered-frame.jpg• U-frame contains two code fields, one two hit and other three bit.

• These five bits can create upto 32 different U-frames.

Protocol Structure - HDLC: High Level Data Link Control

Flag - The value of the flag is always (0x7E).

Address field - Defines the address of the secondary station which is sending the frame or the

destination of the frame sent by the primary station. It contains Service Access Point (6bits), a

Command/Response bit to indicate whether the frame relates to information frames (I-frames) being

sent from the node or received by the node, and an address extension bit which is usually set to true to

indicate that the address is of length one byte. When set to false it indicates an additional byte follows.

Extended address - HDLC provides another type of extension to the basic format. The address field

may be extended to more than one byte by agreement between the involved parties.

Control field - Serves to identify the type of the frame. In addition, it includes sequence numbers,

control features and error tracking according to the frame type.

FCS - The Frame Check Sequence (FCS) enables a high level of physical error control by allowing

the integrity of the transmitted frame data to be checked.

Related Protocols : LAPB , ISDN , X.25 , Frame Relay , SDLC

RESULT:

Thus the High level data link control protocol was studied

Page 120: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

120

STUDY OFNETWORK SIMULATOR AND SIMULATION OF CONGESTION CONTROL

ALGORITHMS USING NS

Aim: To Study of Network simulator (NS).and Simulation of Congestion Control

Algorithms using NS

Introduction: ns (from network simulator) is a name for series of discrete event network

simulators, specifically ns-1, ns-2 and ns-3. All of them are discrete-event network simulator,

primarily used in research[4] and teaching. ns-3 is free software, publicly available under the GNU

GPLv2 license for research, development, and use.

The goal of the ns-3 project is to create an open simulation environment for networking research that

will be preferred inside the research community

It should be aligned with the simulation needs of modern networking research.

x It should encourage community contribution, peer review, and validation of the software.

Since the process of creation of a network simulator that contains a sufficient number of

highquality validated, tested and actively maintained models requires a lot of work, ns-3 project

spreads this workload over a large community of users and developers.

ns-1

The first version of ns, known as ns-1, was developed at VJ,GEEKLIME, Madurai (LBNL) in

the 1995-97 timeframe by Steve McCanne, Sally Floyd, Kevin Fall, and other contributors. This was

known as the LBNL Network Simulator, and derived from an earlier simulator known as REAL by S.

Keshav. The core of the simulator was written in C++, with Tcl-based scripting of simulation

scenarios.[5] Long-running contributions have also come from Sun Microsystems, the UC Berkeley

Daedelus, and Carnegie Mellon Monarch projects.it used.

ns-2

In 1996-97, ns version 2 (ns-2) was initiated based on a refactoring by Steve McCanne. Use of

Tcl was replaced by MIT's Object Tcl (OTcl), an object-oriented dialect Tcl. The core of ns-2 is also

written in C++, but the C++ simulation objects are linked to shadow objects in OTcl and variables can

be linked between both language realms. Simulation scripts are written in the OTcl language, an

extension of the Tcl scripting language. Presently, ns-2 consists of over 300,000 lines of source code,

and there is probably a comparable amount of contributed code that is not integrated directly into the

main distribution (many forks of ns-2 exist, both maintained and unmaintained). It runs on

GNU/Linux, FreeBSD, Solaris, Mac OS X and Windows versions that support Cygwin. It is licensed

for use under version 2 of the GNU General Public License

Page 121: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

121

ns-3

A team led by Tom Henderson, George Riley, Sally Floyd, and Sumit Roy, applied for and

received funding from the U.S. National Science Foundation (NSF) to build a replacement for ns-2,

called ns-3. This team collaborated with the Planete project of INRIA at Sophia Antipolis, with

Mathieu Lacage as the software lead, and formed a new open source project.In the process of

developing ns-3, it was decided to completely abandon backwardcompatibility with ns-2. The new

simulator would be written from scratch, using the C++ programming language. Development of ns-3

began in July 2006. A framework for generating Python bindings (pybindgen) and use of the Waf

build system were contributed by Gustavo Carneiro. The first release, ns-3.1 was made in June 2008,

and afterwards the project continued making quarterly software releases, and more recently has moved

to three releases per year. ns-3 made its eighteenth release (ns-3.18) in the third quarter of 2013.

Current status of the three versions is:

ns-1 is no longer developed nor maintained,

ns-2 build of 2009 is not actively maintained (and is not being accepted for journal publications)

ns-3 is actively developed (but not compatible for work done on ns-2).

Design

ns-3 is built using C++ and Python with scripting capability. The ns-3 library is wrapped to python

thanks to the pybindgen library which delegates the parsing of the ns-3 C++ headers to gccxml and

pygccxml to generate automatically the corresponding C++ binding glue. These automatically-

generated C++ files are finally compiled into the ns-3 python module to allow users to interact with

the C++ ns-3 models and core through python scripts. The ns-3 simulator features an integrated

attribute-based system to manage default and per-instance values for simulation parameters. All of the

configurable default values for parameters are managed by this system, integrated with command-line

argument processing, Doxygen documentation, and an XML-based and optional GTK-based

configuration subsystem. x The large majority of its users focuses on wireless simulations which

involve models for Wi-Fi, WiMAX, or LTE for layers 1 and 2 and routing protocols such as OLSR

and AODV.

Components

ns-3 is split over couple dozen modules containing one or more models for real-world network devices

and protocols.

ns-3 has more recently integrated with related projects: the Direct Code Execution extensions allowing

the use of C or C++-based applications and Linux kernel code in the simulations.

Simulation workflow

The general process of creating a simulation can be divided into several steps:

Page 122: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

122

1. Topology definition: to ease the creation of basic facilities and define their interrelationships, ns-3

has a system of containers and helpers that facilitates this process. 2. Model development: models are

added to simulation (for example, UDP, IPv4, pointto-point devices and links, applications); most of

the time this is done using helpers. 3. Node and link configuration: models set their default values (for

example, the size of packets sent by an application or MTU of a point-to-point link); most of the time

this is done using the attribute system. 4. Execution: simulation facilities generate events, data

requested by the user is logged. 5. Performance analysis: after the simulation is finished and data is

available as a timestamped event trace. This data can then be statistically analysed with tools like R to

draw conclusions. 6. Graphical Visualization: raw or processed data collected in a simulation can be

graphed using tools like Gnuplot, matplotlib or XGRAPH.

Examples of network simulators

There are many both free/open-source and proprietary network simulators.

Examples of notable network simulation software are, ordered after how often they are mentioned in

research papers:

1. ns (open source)

2. OPNET (proprietary software)

3. NetSim (proprietary software)

Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and time involved in

setting up an entire test bed containing multiple networked computers, routers and data links,

network simulators are relatively fast and inexpensive. They allow engineers, researchers to test

scenarios that might be particularly difficult or expensive to emulate using real hardware - for

instance, simulating a scenario with several nodes or experimenting with a new protocol in the

network. Network simulators are particularly useful in allowing researchers to test new networking

protocols or changes to existing protocols in a controlled and reproducible environment. A typical

network simulator encompasses a wide range of networking technologies and can help the users to

build complex networks from basic building blocks such as a variety of nodes and links. With the help

of simulators, one can design hierarchical networks using various types of nodes like computers,

hubs, bridges, routers, switches, links, mobile units etc. Various types of Wide Area Network (WAN)

technologies like TCP, ATM, IP etc. and Local Area Network (LAN) technologies like Ethernet,

token rings etc., can all be simulated with a typical simulator and the user can test, analyze various

standard results apart from devising some novel protocol or strategy for routing etc. Network

simulators are also widely used to simulate battlefield networks in Network-centric warfare

Packet loss:

Page 123: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

123

When one or more packets of data travelling across a computer network fail to reach their destination.

Packet loss is distinguished as one of the three main error types encountered in digital

communications; the other two being bit error and spurious packets caused due to noise. Packets can

be lost in a network because they may be dropped when a queue in the network node overflows. The

amount of packet loss during the steady state is another important property of a congestion control

scheme. The larger the value of packet loss, the more difficult it is for transport layer protocols to

maintain high bandwidths, the sensitivity to loss of individual packets, as well as to frequency and

patterns of loss among longer packet sequences is strongly dependent on the application itself.

Throughput:

This is the main performance measure characteristic, and most widely used. In

communication networks, such as Ethernet or packet radio, throughput or network throughput is the

average rate of successful message delivery over a communication channel. The throughput is usually

measured in bits per second (bit/s or bps), and sometimes in data packets per second or data packets

per time slot This measure how soon the receiver is able to get a certain amount of data send by the

sender. It is determined as the ratio of the total data received to the end to end delay. Throughput is an

important factor which directly impacts the network performance

Delay:

Delay is the time elapsed while a packet travels from one point e.g., source premise or network

ingress to destination premise or network degrees. The larger the valueof delay, the more difficult it is

for transport layer protocols to maintain high bandwidths. We will calculate end to end delay

Queue Length:

A queuing system in networks can be described as packets arriving for service, waiting for service

if it is not immediate, and if having waited for service, leaving thesystem after being served. Thus

queue length is very important characteristic to determine that how well the active queue management

of the congestion control algorithm has been working.

RESULT:

Thus the study of Network simulator (NS2)was studied.

Page 124: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

124

CONTENT BEYOND THE SYLLABUS EXPERIMENTS

IMPLEMENTATION OF REMOTE PROCEDURE CALL

AIM:

To write a java program to implement RPC (remote procedure call)

ALGORITHM:

CLIENT SIDE:

1. Establish a connection between the Client and Server.

Socket client=new Socket("127.0.0.1",6555);

2. Create instances for input and output streams.

Print Stream ps=new Print Stream(client.getOutputStream());

3. BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));

4. Enter the command in Client Window.

Send themessage to its output str=br.readLine();

ps.println(str);

SERVER SIDE:

1. Accept the connection request by the client.

ServerSocket server=new ServerSocket(6555);

Sockets=server.accept();

2. Getthe IPaddressfromitsinputstream.

BufferedReaderbr1=newBufferedReader(newInputStreamReader(s.getInputStream()));

ip=br1.readLine();

3. During runtime execute the process

Runtime r=Runtime.getRuntime();

Process p=r.exec(str);

Clientrpc:

import java.io.*;

import java.net.*;

import java.util.*;

class Clientrpc

{

public static void main(String args[])

{

Page 125: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

125

try

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

Socket clsct=new Socket("18.17.40.27",3128);

DataInputStream din=new DataInputStream(clsct.getInputStream());

DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

System.out.println("Enter String");

String str=in.readLine();

dout.writeBytes(str+'\n');

clsct.close();

}

catch (Exception e)

{ System.out.println(e);

}

}

}

Serverrpc:

import java.io.*;

import java.net.*;

import java.util.*;

class Serverrpc

{

Page 126: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

126

public static void main(String args[])

{

try

{

ServerSocket obj=new ServerSocket(3128);

while(true)

{

Socket obj1=obj.accept();

DataInputStream din=new DataInputStream(obj1.getInputStream()); DataOutputStream dout=new

DataOutputStream(obj1.getOutputStream()); String str=din.readLine();

Process p=Runtime.getRuntime().exec(str);

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

Page 127: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

127

Output:

RESULT:

Thus the implementation RPC is done & executed successfully.

Page 128: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

128

FILE TRANSFER IN CLIENT & SERVER

AIM:

To Perform File Transfer in Client & Server Using TCP/IP.

CLIENT SIDE:

1. Start.

2. Establish a connection between the Client and Server.

3. Socketss=new Socket(InetAddress.getLocalHost(),1100);

4. Implement a client that can send two requests.

a. To get a file from the server.

b. To put or send a file to the server.

5. After getting approval from the server ,the client either get file from the server or send file to the

server.

SERVER SIDE:

1. Start.

2. Implement a server socket that listens to a particular port number.

3. Server reads the filename and sends the data stored in the file for the‘get’ request.

4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’ instruction.

5. Exit upon client’s request.

6. Stop.

Client:

import java.io.*;

import java.net.*;

import java.util.*;

class Clientfile

{

public static void main(String args[])

{

try

{

Page 129: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

129

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

Socket clsct=new Socket("18.17.40.27",3128);

DataInputStream din=new DataInputStream(clsct.getInputStream());

DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());

System.out.println("Enter the file name:");

String str=in.readLine();

dout.writeBytes(str+'\n');

System.out.println("Enter the new file name:");

String str2=in.readLine();

String str1,ss;

FileWriter f=new FileWriter(str2);

char buffer[];

while(true)

{

str1=din.readLine();

if(str1.equals("-1"))

break;

System.out.println(str1);

buffer=new char[str1.length()];

str1.getChars(0,str1.length(),buffer,0);

f.write(buffer);

}

f.close();

clsct.close();

}

Page 130: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

130

catch (Exception e)

{

System.out.println(e);

}

}

}

Server:

import java.io.*;

import java.net.*;

import java.util.*;

class Serverfile

{

public static void main(String args[])

{

try

{

ServerSocket obj=new ServerSocket(3128);

while(true)

{

Socket obj1=obj.accept();

DataInputStream din=new DataInputStream(obj1.getInputStream());

DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());

String str=din.readLine();

FileReader f=new FileReader(str);

BufferedReader b=new BufferedReader(f);

Page 131: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

131

String s;

while((s=b.readLine())!=null)

{

System.out.println(s);

dout.writeBytes(s+'\n');

}

f.close();

dout.writeBytes("-1\n");

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

Page 132: DEPARTMENT OF ELECTRONICS AND COMMUNICATION ...veltechengg.com/wp-content/uploads/2019/08/EC8563-Comm...VIVA QUESTIONS: 1. What is meant by congestion? Congestion in a network occurs

132

Output:

RESULT:

Thus the File transfer Operation is done & executed successfully.