1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.core.bio.udp;
21
22 import java.io.IOException;
23 import java.net.DatagramPacket;
24 import java.net.DatagramSocket;
25 import java.net.InetAddress;
26 import java.util.concurrent.CountDownLatch;
27
28 import org.apache.mina.core.BenchmarkClient;
29
30
31
32
33
34
35 public class BioUdpBenchmarkClient implements BenchmarkClient {
36
37 private DatagramSocket sender;
38
39
40
41
42 public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
43 InetAddress serverAddress = InetAddress.getLocalHost();
44 byte[] buffer = new byte[65507];
45 sender = new DatagramSocket(port + 1);
46
47 DatagramPacket pduSent = new DatagramPacket(data, data.length, serverAddress, port);
48 DatagramPacket pduReceived = new DatagramPacket(buffer, data.length);
49 sender.send(pduSent);
50
51 boolean done = false;
52
53 while (!done) {
54 try {
55 sender.receive(pduReceived);
56
57 for (int i = 0; i < pduReceived.getLength(); ++i) {
58 counter.countDown();
59
60 if (counter.getCount() > 0) {
61 sender.send(pduSent);
62 break;
63 } else {
64 done = true;
65 }
66 }
67 } catch (IOException ioe) {
68
69 }
70 }
71
72 sender.close();
73 }
74
75
76
77
78 public void stop() throws IOException {
79 }
80 }