-
Notifications
You must be signed in to change notification settings - Fork 0
/
gbC.java
76 lines (62 loc) · 1.63 KB
/
gbC.java
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
package swgobackn;
import java.io.*;
import java.net.*;
import java.util.*;
class testclient{
public static void main(String args[])throws IOException
{
InetAddress addr=InetAddress.getByName("Localhost");
System.out.println(addr);
Socket connection=new Socket(addr,5500);
BufferedInputStream in=new BufferedInputStream(connection.getInputStream());
DataOutputStream out=new DataOutputStream(connection.getOutputStream());
Scanner scr=new Scanner(System.in);// this will be used to accept i/p from console
System.out.println(".......Client........");
System.out.println("Connect");
System.out.println("Enter the number of frames to send");
int c=scr.nextInt();
out.write(c);
out.flush();
System.out.println("Enter the type of transmission\n1.Error\n0.No error");
int choice=scr.nextInt();
out.write(choice);
int check=0,i=0,j=0;
if(choice==0)
{
for(j=0;j<c;++j)
{
i=in.read();
System.out.println("Received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i);
out.flush();
}
out.flush();
}
else
{
for(j=0;j<c;++j)
{
i=in.read();
if(i==check)
{
System.out.println("Received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i);
++check;
}
else
{
--j;
System.out.println("Discarded frame no: "+i);
System.out.println("Sending NEGATIVE ack");
out.write(-1);
}
out.flush();
}
}//end of else for error
in.close();
out.close();
System.out.println("Completed!");
}// end of main method
}// end of main class