28.8. Swing Borders

 
[Page 815]

Chapter 25. Networking

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To comprehend socket-based communication in Java ( §25.2).

  • To understand client/server computing ( §25.2).

  • To implement Java networking programs using stream sockets ( §25.2).

  • To obtain Internet addresses using the InetAddress class ( §25.3).

  • To develop servers for multiple clients ( §25.4).

  • To develop applets that communicate with the server ( §25.5).

  • To send and receive objects on a network ( §25.6).

  • To create applications or applets to retrieve files from a network ( §25.7).

  • To render HTML files using the JEditorPane class ( §25.8).

  • (Optional) To implement Java networking programs using datagram sockets ( §25.10).


[Page 816]

25.1. Introduction

To browse the Web or send email, your computer must be connected to the Internet. The Internet is the global network of millions of computers. Your computer may connect to the Internet through an Internet Service Provider (ISP) using dialup, DSL, or cable modem, or through a local area network (LAN).

When a computer needs to communicate with another computer, it needs to know the address of the other computer. This is called an Internet Protocol (IP) address that uniquely identifies the computer on the Internet. An IP address consists of four dotted decimal numbers between and 255 , such as 130.254.204.36 . Since it is not easy to remember so many numbers, they are often mapped to meaningful names called domain names , such as drake.armstrong.edu . There are special servers on the Internet that translate host names into IP addresses. These servers are called Domain Name Servers (DNS). When a computer contacts drake.armstrong.edu , it first asks the DNS to translate this domain name into a numeric IP address and then sends the request using the IP address.

The Internet Protocol is a low-level protocol for delivering data from one computer to another across the Internet in packets. Two higher-level protocols used in conjunction with the IP are the Transmission Control Protocol ( TCP ) and the User Datagram Protocol (UDP). TCP enables two hosts to establish a connection and exchange streams of data. TCP guarantees delivery of data and also guarantees that packets will be delivered in the same order in which they were sent. UDP is a standard, low-overhead, connectionless, host-to-host protocol that is used over the IP. UDP allows an application program on one computer to send a datagram to an application program on another computer.

Java supports stream sockets and datagram sockets. Stream sockets use TCP (Transmission Control Protocol) for data transmission, whereas datagram sockets use UDP (User Datagram Protocol). Since TCP can detect lost transmissions and resubmit them, transmissions are lossless and reliable. UDP, in contrast, cannot guarantee lossless transmission. Because of this, stream sockets are used in most areas of Java programming, and that is why the most of discussion in this chapter is based on stream sockets. Datagram socket programming is introduced in the last section of the chapter.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net