Objectives |
|
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.