17.1. Implementing a Client

The client is the program that initiates a network connection. Implementing a client consists of five basic steps:

1.
Create a Socket object.
2.
Create an output stream that can be used to send information to the Socket.
3.
Create an input stream to read the response from the server.
4.
Do I/O with input and output streams.
5.
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 ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.