This phrase assumes that we've previously created a socket to the server from which we want to write text. See the phrase "Contacting a Server" in this chapter for more details on creating the socket instance. Given the socket instance, we call the getOutputStream() method to get a reference to the socket's output stream. With that, we instantiate a PrintWriter for writing text across the network to the server with which we are connected. The second parameter that we pass to the PrintWriter constructor in this phrase sets the auto-flush option. Setting this to true will cause the println(), printf(), and format() methods to automatically flush the output buffer. In our phrase, we use the print() method; thus, we must follow that by a call to the flush() method to force the data across the network. |