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.
Solutions15.12.3Solutions to Self-Study Exercises
15.2An Overview of Networks 15.2.2Internets
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.
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.4Client/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.5The SlideShow Application 15.5.5The Timer Class
15.9Playing One Row Nim Over the Network 15.9.4Self-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.
If you specify the wrong host name, you will get the following exception: java.net.ConnectException: Connection refused.
If you specify the wrong port, you will get the following exception: java.net.ConnectException: Connection refused.
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}