Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

15. Networking and Threads: Make a Conne... > To write data to a Socket, use a Pri...

To write data to a Socket, use a PrintWriter

We didn’t use PrintWriter in the last chapter, we used BufferedWriter. We have a choice here, but when you’re writing one String at a time, PrintWriter is the standard choice. And you’ll recognize the two key methods in PrintWriter, print() and println()! Just like good ol’ System.out.

  1. Make a Socket connection to the server

    image with no caption
  2. Make a PrintWriter chained to the Socket’s low-level (connection) output stream

    image with no caption
  3. Write (print) something

    image with no caption
    image with no caption

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint