Java Reference
In-Depth Information
... GUI code from the WhoisApplet program ...
/** Connect to the whois service via a socket. Write the
* address with a PrintWriter object and read the
* output via a BufferedReader. Send the output to the
* text area. **/
public void whoisConnect (String query - address) {
int port = 43; // Standard whois port
String reply;
try {
Socket whois - socket =
new Socket ("whois.internic.net", port);
PrintWriter print - writer =
new PrintWriter (whois - socket.getOutputStream (),
true);
print - writer.println (query - address);
InputStreamReader input - reader =
new InputStreamReader
(whois - socket.getInputStream ());
BufferedReader buf - reader =
new BufferedReader (input - reader);
while ((reply = buf - reader.readLine ()) ! = null) {
// Write the whois info to the textarea.
fTextArea.append (reply + ' \ n ' );
}
fTextArea.append ( " \ n \ n " );
// Add space between queries
}
catch (IOException e) {
fTextArea.append ("IO Exception ="+ e);
System.out.println ("IO Exception ="+ e);
return;
}
}
...
Figure 13.4 shows the program interface with the output of a typical case. Though
written in applet form, the security manager in most browser JVMs blocks
 
Search WWH ::




Custom Search