Skip to main content
Logo image

Java, Java, Java: Object-Oriented Problem Solving, 2022E

Section 15.12 Chapter Summary

Subsection 15.12.1 Technical Terms

Table 15.12.1.
busy waiting callback method client
client/server protocols domain name ethernet protocol
File Transfer Protocol (FTP) get HyperText Transfer Protocol (HTTP)
internet Internet Internetworking Protocol (IP)
Java Server Page (JSP) packet port
post protocol router
sandbox security model scriptlet server
servlet Simple Mail Transfer Protocol (SMTP) socket
trusted code Uniform Resource Locator (URL) World Wide Web (WWW)

Subsection 15.12.2 Summary of Important Points

  • An internet is a collection of two or more distinct networks joined by routers, which have the task of translating one network’s language to the other’s. The Internet is a network of networks that uses the Internet Protocol (IP) as the translation medium.
  • A protocol is a set of rules that controls the transfer of information between two computers in a network. The HyperText Transfer Protocol (HTTP) governs information exchange on the World Wide Web (WWW). The Simple Mail Transfer Protocol controls mail service on the Internet. The File Transfer Protocol (FTP) controls the transfer of files between Internet computers. The Domain Name System (DNS) governs the use of names on the Internet.
  • A client/server application is one that divides its task between a client, which requests service, and a server, which provides service. Many Internet applications and protocols are based on the client/server model.
  • Lower-level protocols, such as the ethernet protocol and token ring protocol, govern the transmission of data between computers on a single network. The Internet Protocol (IP) translates between such protocols.
  • A Uniform Resource Locator (URL) is a standard way of specifying addresses on the Internet. It consists of several parts separated by slashes and colons: method://host:port/path/file. The java.net.URL class is used to represent URLs.
  • Files of text or data (images, audio files) on the Internet or Web can be downloaded using the same InputStream s and OutputStream s as files located on a disk. To read or write a resource located on a network, you need to connect its URL to an input or output stream.
  • The java.awt.Toolkit class contains useful methods for downloading Image s into an application.
  • A socket is a two-way communication channel between two running programs on a network. The java.net.Socket class can be used to set up communication channels for client/server applications. The server process listens at a socket for requests from a client. The client process requests service from a server listening at a particular socket. Once a connection exists between client and server, input and output streams are used to read and write data over the socket.

Solutions 15.12.3 Solutions to Self-Study Exercises

15.2 An Overview of Networks
15.2.2 Internets

Self-Study Exercises
15.2.2.1. Matching Problem for Topologies.
Solution.
  • The bus topology requires the least cables, and the fully connected mesh topology requires the most cables.
  • The fully connected mesh topology would have the most potential to use alternate routes if one of the host computers crashed.
  • The star topology would be rendered completely useless if its central hub crashed.

15.2.3 Network Protocols
15.2.3.1 Application Protocols

Self-Study Exercise
15.2.3.1.1. URL parts.
Solution.
The protocol is http. The host computer is named www. The domain name is github, and it is part of the com(commercial) Internet domain.

15.2.4 Client/Server Applications

Self-Study Exercise
15.2.4.1. Client-Server Exercise.
Solution.
  • For buying a piece of software at a bookstore, the server would be the sales clerk. The protocol would be to select the software from off the shelf, bring it to the checkout counter, give the sales clerk money, and get a receipt.
  • For buying a piece of software over the phone, the server would be the telephone sales clerk. The protocol would be to select from a catalog, provide the sales clerk with your credit card information, and say goodbye.
  • For buying a piece of software over the Internet, the server would be the computer that handles the transaction. The protocol would be to select the item from a Web-based form, provide the form with personal and payment information, and click on the Buy button. \end{ANSBL}

15.5 The SlideShow Application
15.5.5 The Timer Class

Self-Study Exercise
15.5.5.2. Design Soundtrack.
Solution.
To play sounds along with slides in the SlideShowFrame, you would make the following modifications to the code:
private Clip soundClip[] = new Clip[NIMGS];
private Clip currentClip = null;
Declare an array of URL s to store the URLs of the audio files you want to play. Assign Clips to the array at the same time you input the images:
for (int k=0; k < NIMGS; k++) {
  url =
   new URL( "http://www.cs.trincoll.edu/~ram/jjj/slide" +
                                              k + ".gif");
  slide[k] = imageIO.read( url );
  URL soundURL =
   new URL("http://www.cs.trincoll.edu/~ram/jjj/sound" +
                                               k + ".au");
  AudioInputStream audio =
    AudioSystem.getAudioInputStream(url);
  DataLine.Info info = new DataLine.Info(Clip.class,
               audio.getFormat());
  soundClip[k] = (Clip) AudioSystem.getLine(info);
}
Change the nextSlide() code to the following
public void nextSlide() {
    currentClip.stop(); // stop sound playback
    currentClip = soundClip[nextImg]; // get next soundClip
    currentClip.setFramePosition(0); // start clip at beginning
    currentImage = slide[nextImg];
    nextImg = ( nextImg + 1) % NIMGS;
    repaint ();
  }
Each time an image is displayed in paint(), play the corresponding sound by using the URL from the array:
public void paint(Graphics g) {
    if (currentImage != null) {
        g.drawImage(currentImage,10,10,this);
        currentClip.start();
    }
  }

15.6 The Real-Estate Application
15.6.11 Self-Study Exercise

15.9 Playing One Row Nim Over the Network
15.9.4 Self-Study Exercise

15.9.4.1. Scramble Service.
Solution.
The scramble service would be implemented by defining two new classes: The ScrambleServer class is a subclass of Server, and the ScrambleClient class is a subclass of Client. The ScrambleClient would implement the requestService() method and the ScrambleServer would implement the provideService() method.
15.9.4.2. Connection Errors.
Solution.
  1. If you specify the wrong host name, you will get the following exception: java.net.ConnectException: Connection refused.
  2. If you specify the wrong port, you will get the following exception: java.net.ConnectException: Connection refused.
  3. If you leave off the \n in the writeToSocket() call, nothing will go wrong because the writeToSocket() method will catch this error and add the end-of-line character to the string before sending it to the server. The server reads lines from the client, so every communication must end with \n or the protocol will break down. \end{ANSBL}
You have attempted of activities on this page.