String str = (args.length == 0 ? "" : args[0]) + "\n";
// Convert to bytes.
byte buf[] = str.getBytes();
// Send request.
// Read and display response.
while ((c = != -1) {
System.out.print((char) c);
If, for example, you obtained information about, you'd get something similar
to the following:
Whois Server Version 1.3
Domain names in the .com, .net, and .org domains can now be registered
with many different competing registrars. Go to
for detailed information.
Domain Name: OSBORNE.COM
Whois Server:
Referral URL:
Name Server: NS1.EPPG.COM
Name Server: NS2.EPPG.COM
Here is how the program works. First, a Socket is constructed that specifies the host
name "" and the port number 43. is the InterNIC web site that
handles whois requests. Port 43 is the whois port. Next, both input and output streams are
opened on the socket. Then, a string is constructed that contains the name of the web site you
want to obtain information about. In this case, if no web site is specified on the command
line, then "" is used. The string is converted into a byte array and then sent out of
the socket. The response is read by inputting from the socket, and the results are displayed.
The preceding example was rather obscure because the modern Internet is not about the
older protocols such as whois, finger, and FTP. It is about WWW, the World Wide Web. The
Web is a loose collection of higher-level protocols and file formats, all unified in a web
browser. One of the most important aspects of the Web is that Tim Berners-Lee devised a
scaleable way to locate all of the resources of the Net. Once you can reliably name anything
and everything, it becomes a very powerful paradigm. The Uniform Resource Locator
(URL) does exactly that.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks