17.7. Implementing a Server
The server is the program that starts first and waits for incoming connections. Implementing a server consists of six basic steps:
Create a ServerSocket object.
Create a Socket object from the ServerSocket.
Create an input stream to read input from the client.
Create an output stream that can be used to send information back to the client.
Do I/O with input and output streams.
Close the Socket when done.
Each of these steps is described in more detail in the following sections. As with the client, note that most of the methods described throw an IOException, so they need to be wrapped inside a try/catch block in an actual implementation.
Create a ServerSocket object. With a client socket, you ...