String serverName = "www.timothyfisher.com"; Socket sock = new Socket(serverName, 80);
In this phrase, we connect to a server via TCP/IP using Java’s Socket class. During construction of the sock instance in our phrase, a socket connection will be made to the server specified by serverName—in this case, www.timothyfisher.com and port 80.
Whenever a Socket is created, you must be sure to close the socket when you are finished with it by calling the close() method on the Socket instance you are working with.
Java supports other ways of connecting to a server that we won’t discuss details of here. For example, you could use the URL class to open a URL and read from it. See the phrase “Reading a Web Page via HTTP” in this chapter ...