17.1. Implementing a Client
The client is the program that initiates a network connection. Implementing a client consists of five basic steps:
Create a Socket object.
Create an output stream that can be used to send information to the Socket.
Create an input stream to read the response from the server.
Do I/O with input and output streams.
Close the Socket when done.
Each of these steps is described in the sections that follow. Note that most of the methods described in these sections throw an IOException and need to be wrapped in a try/catch block.
Create a Socket object. A Socket is the Java object corresponding to a network connection. A client connects to an existing server that is listening on a numbered network port ...