Java Reference
In-Depth Information
1. Don't do it.
2. (For experts only) OK, do it but only after you have clear and unambiguous meas‐
urements proving you have a problem, and that will clearly show whether your
changes have fixed the problem.
An Example Client
Although the new I/O APIs aren't specifically designed for clients, they do work for
them. I'm going to begin with a client program using the new I/O APIs because it's a
little simpler. In particular, many clients can be implemented with one connection at a
time, so I can introduce channels and buffers before talking about selectors and non‐
blocking I/O.
A simple client for the character generator protocol defined in RFC 864 will demonstrate
the basics. This protocol is designed for testing clients. The server listens for connections
on port 19. When a client connects, the server sends a continuous sequence of characters
until the client disconnects. Any input from the client is ignored. The RFC does not
specify which character sequence to send, but recommends that the server use a rec‐
ognizable pattern. One common pattern is rotating, 72-character carriage return/line‐
feed delimited lines of the 95 ASCII printing characters, like this:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghi
#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij
$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijk
%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkl
&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklm
I picked this protocol for the examples in this chapter because both the protocol for
transmitting the data and the algorithm to generate the data are simple enough that they
won't obscure the I/O. However, chargen can transmit a lot of data over a relatively few
connections and quickly saturate a network. It's thus a good candidate for the new I/O
APIs.
Chargen is not commonly used these days, and may be blocked by local
firewalls even if it's turned on. It's vulnerable to a “ping-pong” denial-
of-service attack, in which spoofed Internet packets cause two hosts to
spew an unlimited amount of data at each other. Furthermore, be‐
cause it's almost infinitely asymmetric—the server sends an unlimi‐
ted amount of data in response to the smallest of client requests—it's
very easy for even a few dozen compromised hosts, much less a large
botnet, to convince a chargen server to saturate its local bandwidth.
 
Search WWH ::




Custom Search