GOBACKNARQ
GOBACKNARQ
GOBACKNARQ
ASSIGNMENT: 2
PRIYANKA KARIYA
192011036
FYMCA
PROGRAM
client.java
import java.lang.System;
import java.net.*;
import java.io.*;
}
for (int i = 0; i < p; i++)
if (v[i] == -1) {
System.out.println("Request to retransmit from
packet no "
+ (i+1) + " again!!");
n = i;
out.write(n);
out.flush();
}
System.out.println();
v[n] = in.read();
System.out.println("Received frame is: " +
v[n]);
System.out.println("quiting");
} catch (Exception e) {
System.out.println(e);
}
}
}
server.java
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
try {
int a[] = { 30, 40, 50, 60, 70, 80, 90, 100 };
Serversocket = new ServerSocket(8011);
System.out.println("waiting for connection");
Socket client = Serversocket.accept();
dis = new DataInputStream(client.getInputStream());
dos = new
DataOutputStream(client.getOutputStream());
System.out.println("The number of packets sent is:" +
a.length);
int y = a.length;
dos.write(y);
dos.flush();
for (int i = 0; i < a.length; i++) {
dos.write(a[i]);
dos.flush();
}
int k = dis.read();
dos.write(a[k]);
dos.flush();
} catch (IOException e) {
System.out.println(e);
} finally {
try {
dis.close();
dos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
OUTPUT: