Experiment 8 Go Back N using UDP PDF

Title Experiment 8 Go Back N using UDP
Course Computer Science Engineering
Institution University of Calicut
Pages 14
File Size 396.7 KB
File Type PDF
Total Downloads 22
Total Views 144

Summary

To implement a Go Back N ARQ protocol using UDP socket communication...


Description

Experiment 10

Go Back N using UDP 10.1

Aim

To implement a Go Back N ARQ protocol using UDP socket communication.

10.2

Theoretical Background

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 ACK packet from the receiver. The receiver process keeps track of sequence number of the next frame it expects to receive, and sends that number with every ACK it sends. The receiver will ignore any frame that does not have the exact sequence number it expects – whether that frame is a “past” duplicate of a frame it has already ACK’ed, or whether that frame is a “future” frame past the lost packet it is waiting for. 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 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. A sample of communication sequence is shown in figure 10.1

10.3

Algorithm

Go Back N-Sender 1. Start 2. Create the client UDP socket. 81

Experiment-10 Go Back N using UDP

Figure 10.1: Go Back N process communication sequence.

3. Send the message Client request for a UDP connection to the server. 4. This is done so that the server understands the address of the client. 5. Read the first message from the server using client socket and print it. 6. While true, do the following (a) Read the data from the keyboard and send to Receiver. (b) Receive the packet from the server. (c) If the packet has, ACK of a character, send data from that character onwards. (d) Else, it has NAK of a character. So send characters again from that character. End while 7. Stop

Go Back N Receiver 1. Start 2. Server creates an UDP SOCKET 3. Initialize char c = 97 4. Server reads the message from client and gets the clients address. 5. Server demand the client to send data as its first message. 6. While true, do the following Network Programming Lab Manual

82

Experiment-10 Go Back N using UDP (a) Read the data packet from client to String mesg (b) Convert it to character array ch (c) c=65 /*ascii value for ’A’ */ (d) for i=0 to ch.length if ( ch[i] != c ) then break if(c==91) c=65 /*if c reaches ’Z’, reset to ’A’*/ c++ End for loop (e) If i == ch.length then Send ACK of c Print ”Requesting client to continue from: c (f) Else Send NAK of c Print ”Requesting client to resend from : c

End while 7. Stop

10.4

Program

/*Go Back N Sender

sender.java*/

import java.io.*; import java.net.*; import java.lang.Exception; class Sender{ public static void main(String args[]) throws Exception { DatagramSocket ds=new DatagramSocket(8085); byte buffer[]=new byte[1024]; char ch[]=new char[10]; String str="";

System.out.println("Enter the packets from a-z"); DataInputStream dt=new DataInputStream(System.in); DatagramPacket p=new DatagramPacket(buffer,buffer.length); while(true) {

Network Programming Lab Manual

83

Experiment-10 Go Back N using UDP str=dt.readLine(); str=str.toUpperCase(); buffer=str.getBytes(); ds.send(new DatagramPacket(buffer,buffer.length,InetAddress.getLocalHost(),8086)); ds.receive(p); str=new String(p.getData(),0,p.getLength()); System.out.println("From Receiver: "+str); ch=str.toCharArray(); if(ch[0]==’A’)//

success

{ System.out.println(" continue from "+ch[3]); } else { System.out.println("Resend the packets from "+ch[3]); } } } }

/*Go Back N receiver, receiver.java*/ import java.io.*; import java.net.*; import java.lang.Exception; class Receiver{ public static void main(String args[]) throws Exception { DatagramSocket ds=new DatagramSocket(8086); byte buffer[]=new byte[1024]; DatagramPacket p=new DatagramPacket(buffer,buffer.length); char ch[]=new char[10]; char c=65,i; while(true) { ds.receive(p); String str=""; str=new String(p.getData(),0,p.getLength()); System.out.println("Received packets "+str); ch=str.toCharArray(); for(i=0;i...


Similar Free PDFs