-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopWaitClient.java
More file actions
28 lines (24 loc) · 1009 Bytes
/
StopWaitClient.java
File metadata and controls
28 lines (24 loc) · 1009 Bytes
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
import java.net.*;
public class StopWaitClient {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
ds.setSoTimeout(2000);
for (int i = 0; i < 5; i++) {
byte[] data = ("Frame" + i).getBytes();
while (true) {
System.out.println("Send: Frame" + i);
ds.send(new DatagramPacket(data, data.length, InetAddress.getByName("localhost"), 9090));
try {
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
ds.receive(dp);
System.out.println("Got: " + new String(dp.getData(), 0, dp.getLength()) + "\n");
break;
} catch (SocketTimeoutException e) {
System.out.println("Timeout! Retry...\n");
}
}
}
ds.close();
}
}