-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGoBackNClient.java
More file actions
96 lines (77 loc) · 1.91 KB
/
Copy pathGoBackNClient.java
File metadata and controls
96 lines (77 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.*;
import java.io.*;
import java.net.*;
class GoBackNClient
{
public static void main(String[] args)
{
try
{
Socket s=new Socket("localhost",6665);
String[] input = {"1","2","3","4", "5", "6","7"};
Thread t=new Thread();
String str;
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
DataInputStream dis=new DataInputStream(s.getInputStream());
int j=input.length;
int i=0;
Calendar c3 = Calendar.getInstance();
int window=4;
Calendar c1= Calendar.getInstance();
System.out.println("");
long c2 = c1.getTimeInMillis();
System.out.println("");
long c4 = c3.getTimeInMillis();
System.out.println("");
long c6 = c1.getTimeInMillis();
System.out.println("Timer started. ");
for (int k = 0; k < window; k++)
{
if(k==1)
System.out.println("");
System.out.println("Frame "+(k+1)+" sent");
dout.writeUTF(input[k]);
System.out.println("");
dout.flush();
t.sleep(3000);
if (k==0)
{
str=(String)dis.readUTF();
System.out.println("ÄCK received is = "+str);
}
}
System.out.println("");
System.out.println("Time has run out.Frame 2 was not received");
System.out.println("Resending frames");
for (int k = 1; k < window; k++)
{
System.out.println("Frame "+(k+1)+" sent\n");
dout.writeUTF(input[k]);
dout.flush();
t.sleep(3000);
str=(String)dis.readUTF();
System.out.println("ACK received = "+str);
}
dout.close();
s.close();
}
catch(Exception e){System.out.println(e);}
}
}
/*
OUTPUT:
Timer started.
Frame 1 sent
ÄCK received is = 2
Frame 2 sent
Frame 3 sent
Frame 4 sent
Time has run out.Frame 2 was not received
Resending frames
Frame 2 sent
ACK received = 3
Frame 3 sent
ACK received = 4
Frame 4 sent
ACK received = 5
*/