Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
124 CHAPTER 4 Introduction to Ruby FIGURE 4.8 Active Record in Action these methods. Trying the different methods in the DBI and Active Record classes is the best way to become more proficient in both of these access methods. NETWORK OPERATIONS The ability to easily manipulate binary protocols makes Ruby ideal for communi- cating with complex binary protocols. This section focuses on the basics of reading and writing to network sockets. We will explore TCP and UDP communications by looking at clients and servers individually, and investigating multiple methods for handling incoming connections and concurrency. Client communications In Chapter 2, we touched on client communications with Python, and again in Chapter 3 with Perl. Now, using Ruby, we will see similarities to the previous code, and we will build on it in the final project of this chapter. Let's start with a basic TCP class that we can use to send raw HTTP requests. Sometimes system administrators make compromises in security for a little ease of use. Let's examine a hypothetical case. Our system administrator has created a top-secret PHP script called logview.php in order to look at server logs from anywhere. Since the script isn't linked anywhere, our administrator feels it's secure enough in the Web root. Let's look at the steps the administrator has taken to create and allow his Web script to work. <?php print "<pre>" ; print passthru('cat /var/log/apache2/access.log'); ?> The PHP code prints out a pre HTML tag to indicate that the output has been preformatted. It then executes the cat command on the Web access log and uses the PHP passthru command to print the output to the screen. This is a quick and easy