Está en la página 1de 13

Mahatma Education Societys

Pillai HOC College of Engineering and Technology, Rasayani


Department of Computer Engineering
OSAY 2017-18

Lab Manual
Computer Networks
Sem-V

Prof. RAHUL JIWANE Submitted By:


Student Name
Subject Incharge Class: TE COMP. Div: ---
Experiment List
(As Per University Syllabus)

1. Study of LAN Topology.


2. Study of various Network devices.
3. Building of any topology using Network tool.
4. Installation & Configuration of NS2 in Linux environment.
5. Basic wired & wireless topology in NS2.
6. Build class A & Class B Network using router in Network tool.
7. Implement sub-netting concept using Network tool.
8. Write a program to implement find out class of a given IP address, subnet
mask& first & last IP address of that block.
9. Write a program to build client-server model on different computers.
10. Congestion Control: Stop & Wait, Sliding Window & Selective Repeat, Go
Back n.
Experiment No. 09
Write a program to build client-server model on different computers.

Name of the Student:-__________________________________________________

Roll No.____________ Subject:-_________________________

Date of Practical Performed:-___________ Staff Signature with Date:

//SENDER PROGRAM

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

//RECEIVER PROGRAM

import java.io.*;
import java.net.*;
public class Reciever{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Reciever(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2004,10);
System.out.println("waiting for connection...");
connection=reciever.accept();
sequence=0;
System.out.println("Connection established :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
do{
try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
}
else
{
System.out.println("\n\nreceiver >"+packet +" duplicate data");
}
if(i<3){
out.writeObject(String.valueOf(sequence));i++;
}
else{
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}
}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended .");
}
catch(Exception e){}
finally{
try{
in.close();
out.close();
reciever.close();
}
catch(Exception e){}
}
}
public static void main(String args[]){
Reciever s=new Reciever();
while(true){
s.run();
}
}
}
Conclusion:

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

Frequently Asked Questions

1.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
--------------------------------------------

2.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------
3.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
------------------------------------------

4.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------

5.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
---------------------------
Experiment No. 10
Congestion Control: Stop & Wait, Sliding Window & Selective Repeat, Go
Back n.

Name of the Student:-__________________________________________________

Roll No.____________ Subject:-_________________________

Date of Practical Performed:-________Staff Signature with Date:

Aim: Stop & wait protocol using sockets in java

Theory:
Error Control
When data-frame is transmitted there are probabilities that data-frame may be lost in
the transit or it is received corrupted. In both scenarios, the receiver does not receive
the correct data-frame and sender does not know anything about any loss. In these
types of cases, both sender and receiver are equipped with some protocols which
helps them to detect transit errors like data-frame lost. So, either the sender
retransmits the data-frame or the receiver may request to repeat the previous data-
frame.
Requirements for error control mechanism:
Error detection: The sender and receiver, either both or any, must ascertain
that theres been some error on transit.
Positive ACK: When the receiver receives a correct frame, it should
acknowledge it.
Negative ACK: When the receiver receives a damaged frame or a duplicate
frame, it sends a NACK back to the sender and the sender must retransmit the correct
frame.
Retransmission: The sender maintains a clock and sets a timeout period. If an
acknowledgement of a data-frame previously transmitted does not arrive in the
timeout period, the sender retransmit the frame, thinking that the frame or its
acknowledge is lost in transit.
There are three types of techniques available which Data-link layer may deploy to
control the errors by Automatic Repeat Requests (ARQ):
STOP-AND-WAIT ARQ
The following transition may occur in Stop-and-Wait ARQ:
o The sender maintains a timeout counter. When a frame is sent the sender
starts the timeout counter. If acknowledgement of frame comes in time, the sender
transmits the next frame in queue. If acknowledgement does not come in time, the
sender assumes that either the frame or its acknowledgement is lost in transit. Sender
retransmits the frame and starts the timeout counter. If a negative acknowledgement
is received, the sender retransmits the frame.

Conclusion: -----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
Frequently Asked Questions

1.

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
---------------------------------------------------------------------

2.

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------

3.

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
-------------------------------------------------------------------

4.

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------

5.

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
-----------------------------------------------

También podría gustarte