Writing a Protocol Handler
To demonstrate a complete protocol handler, let’s write one for the finger protocol, which is defined in RFC 1288 and was introduced in Chapter 10. Finger is a relatively simple protocol compared to JDK-supported protocols such as HTTP and FTP. The client connects to port 79 on the server and sends a list of usernames followed by a carriage return/linefeed pair. The server responds with ASCII text containing information about each of the named users or, if no names were listed, a list of the currently logged in users. For example:
% telnet rama.poly.edu 79
Trying 128.238.10.212...
Connected to rama.poly.edu.
Escape character is '^]'.
Login Name TTY Idle When Where
jacola Jane Colaginae *pts/7 Tue 08:01 208.34.37.104
marcus Marcus Tullius pts/15 13d Tue 17:33 farm-dialup11.poly.e
matewan Sepin Matewan *pts/17 17: Thu 15:32 128.238.10.177
hengpi Heng Pin *pts/10 Tue 10:36 128.238.18.119
nadats Nabeel Datsun pts/12 56 Mon 10:38 128.238.213.227
matewan Sepin Matewan *pts/8 4 Sun 18:39 128.238.10.177
Connection closed by foreign host.Or, requesting information about a specific user:
%telnet rama.poly.edu 79Trying 128.238.10.212... Connected to rama.poly.edu. Escape character is '^]'.marcusLogin Name TTY Idle When Where marcus Marcus Tullius pts/15 13d Tue 17:33 farm-dialup11.poly.e
Since there’s no standard for the format of a finger URL, we will start by creating one. Ideally, this should look as much like an http URL as possible. Therefore, we will implement ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access