Java Reference
In-Depth Information
See Also
There are many better structured ways to write a chat client, including WebSockets, RMI,
and JMS. RMI is Java's RPC interface, and is included both in Java SE and in Java EE; it is
not described in this edition of this topic, but you can find the RMI chapter from previous
editions on the author's website . The other technologies are part of the Java Enterprise so,
again, we refer you to Arun Gupta's Java EE 7 Essentials (O'Reilly).
If you need to encrypt your socket connection, check out Sun's JSSE (Java Secure Socket
Extension). (If you took our earlier advice and used the standard HTTP protocol, you can en-
crypt the conversation just by changing the URL to https).
For a good overview of network programming from the C programmer's point of view, see
the late W. Richard Stevens' Unix Network Programming . Despite the topic's name, it's
really about socket and TCP/IP/UDP programming and covers all parts of the (Unix) net-
working API and protocols such as TFTP in amazing detail.
Program: Simple HTTP Link Checker
Checking links is an ongoing problem for website owners as well as those who write technic-
al documentation that links to external sources (e.g., people like the author of the topic you
are now reading). Link Checkers are the tool they inevitably use to validate the links in their
pages, be they web pages or book pages. Implementing a link checker is basically a matter of
(a) extracting links and (b) opening them. Thus, this program. I call it KwikLinkChecker as
it is a bit on the “quick and dirty” side—it doesn't validate the content of the link to be sure it
still contains what it once did, so if, say, an open source project forgets to renew its domain
registration, and it gets taken over by a porn site, well, KwikLinkChecker will never know.
But that said, it does its job reasonably well, and reasonably quickly:
/**
* Check one HTTP link; not recursive. Returns a LinkStatus with
* boolean success, and the filename or an error message in the
* message part of the LinkStatus. The end of this method is one of
* the few places where a whole raft of different "catch" clauses is
* actually needed for the intent of the program.
*/
public
public LinkStatus check ( String urlString ) {
URL url ;
HttpURLConnection conn = null
null ;
HttpURLConnection . setFollowRedirects ( false
false );
Search WWH ::




Custom Search