Lesson 16Network Programming Basics

Computers connected to a network can communicate with each other only if they agree on the rules of communication, called protocols, that define how to request the data, if the data should be sent in pieces, how to acknowledge received data, if the connection between two computers should remain open, and so on. TCP/IP, UDP/IP, FTP, HTTP, and WebSocket are some examples of network protocols.

Local area network (LAN) refers to a computer network connecting devices in a small area—for example, the same office or house, or a rack. Interconnected computers located farther apart or that belong to different companies are part of a wide area network (WAN). The Internet consists of millions of networks and individual devices. Connected networks that belong to the same organization are referred to as an intranet. For security reasons intranets are shielded from the rest of the world by special software called firewalls. This lesson introduces networking using HTTP protocol and sockets.

The World Wide Web (WWW) uses uniform resource locators (URLs) to identify online resources. For example, the following URL says that there is (or will be generated on the fly) a document called training.html located at the remote host known as mycompany.com, and that the program should use the HTTP protocol to request this document. It also states that this request has to be sent via port 80.

http://www.mycompany.com:80/training.html

The hostname must be unique, and ...

Get Java Programming 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.