Java Reference
In-Depth Information
There is one major difference between selecting TCP channels and selecting datagram
channels. Because datagram channels are truly connectionless (despite the connect()
method), you need to notice when the data transfer is complete and shut down. In this
example, you assume the data is finished when all packets have been sent and one minute
has passed since the last packet was received. Any expected packets that have not been
received by this point are assumed to be lost in the ether.
A typical run produced output like this:
Wrote: 0
Read: 0
Wrote: 1
Wrote: 2
Read: 1
Wrote: 3
Read: 2
Wrote: 4
Wrote: 5
Wrote: 6
Wrote: 7
Wrote: 8
Wrote: 9
Wrote: 10
Wrote: 11
Wrote: 12
Wrote: 13
Wrote: 14
Wrote: 15
Wrote: 16
Wrote: 17
Wrote: 18
Wrote: 19
Wrote: 20
Wrote: 21
Wrote: 22
Read: 3
Wrote: 23
...
Wrote: 97
Read: 72
Wrote: 98
Read: 73
Wrote: 99
Read: 75
Read: 76
...
Read: 97
Read: 98
Read: 99
Echoed 92 out of 100 sent
Success rate: 92.0%
Search WWH ::




Custom Search