Notes
Java Network Programming Notes
N5
A basic concept of network
Chapter2 Basic Network Concepts
2.1 Networks
Keywords:network, node, host, address, name, packet-switched, protocol
A network is a collection of computers and other devices that can send and receive data to and from each other more or less in real time.
Each machine on the network is called a node, and most nodes are computers, but printers, routers, bridges, gateways, dumb terminals and Coca-Cola machines can be nodes, but you usually only talk to other computers.
A fully functional computer node is called a host.
Each network node has an address: a sequence of bytes that uniquely identifies it. In different networks, the method of address assignment is the same. The Ethernet address is attached to the physical Ethernet hardware. The device manufacturer should ensure that the addresses of these hardware are not duplicated. The Internet address of a computer is typically assigned by an organization that is responsible for assigning addresses. The addresses that these organizations can assign are also provided by the organization's ISP (Internet Service Provider). An ISP obtains an IP address (Internet Protocol address) from one of three Internet regional registries. For example, registries in the Americas and Africa are ARIN (the American Registry for Internet Numbers). The addresses of the regional registries are also allocated by the IANA (Internet assigned Numbers authority).
In some kinds of networks, nodes can use human-readable names. The correspondence of the name and address is not invariant. The name changed, the address can not change, the address changed, the name can not change. An address can usually have multiple names, and a name can correspond to multiple addresses (though this is rarely the case)
All modern computer networks are packet-switched (packet-switched) networks. The data transmitted over the network is divided into packets, each of which is handled independently. Each package contains "who sent Me" and "Where do I Go" information. The biggest advantage of packet switching is that many exchanges can be made at the same time, and several computers can share a single cable.
A protocol (protocol) is a set of precise sets of rules that define how computers communicate, including address formats, how data is divided, and so on. A publicly released agreement allows software and equipment from different vendors to communicate with each other. Web browsers, for example, don't care whether the server is a UNIX workstation or a Windows box or Mac, because servers and browsers use the same platform-independent HTTP protocol to talk to.
2.2 The Layers of a network
Standard TCP/IP four-tier model:
Application Layer
Transport Layer (TCP,UDP)
Internetlayer (IP)
The Host-to-network Layer (Ethernet,localtalk,fddi ...)
90% of Java Network programming is in the application layer and only needs to be dialogue with the transport layer. The remaining 10% is in the transport layer, with the application layer and the network layer dialogue.
The application layer appears to be directly in conversation with the other host's application layer, and the network creates a logical link between the two application tiers.
2.2.1 The host-to-network Layer
(also known as Link layer,data link layer, Network-interface layer)
This layer defines a particular network interface, such as an Ethernet card, that sends IP packets to the local network or the world through its physical connection.
The physical layer is transparent to java. The data link layer has no direct impact on Java programmers. However, the data you send at the application level can be optimized to accommodate the local packet size of the specific data link layer (the native packet size of a particular data link layer), which will improve performance. However, the optimizer does not run correctly.
2.2.2 The Internet Layer
In the OSI model, the INTERNET layer corresponds to a more generalized name, network layer. A network layer protocol defines how bits and bytes are organized as packets, and how different machines find each other's address scheme. Internet Protocol (IP) is the most widely used network layer protocol and is the only network layer protocol that Java understands. Other network layer protocols include the IPX protocol on the NetWare network, the AppleTalk protocol on the Mac, and the NetBEUI protocol on Windows. The various network layer protocols are independent of the bottom layer, and appletalk,ip,ipx and NetBEUI can be used for Ethernet, Token Ring, or network with other data link layer protocols, and these data link layer protocols themselves can run on different kinds of physical layers.
Internet layer packets are called datagrams, and each IP datagram includes a 20~60 byte header and a maximum of 65515 bytes of data. (In fact, most IP datagram are very small)
The contents of the IP packet header are:
4-bit Version number
4-bit Head length
1-byte Type of Service
2-byte datagram Length: including length of head
2-byte Identification number
3-bit Flags
13-bit Fragment Offset
1-byte time-to-live (TTL)
1-byte Protocol:tcp is 6,udp 17 (all the protocols to the transport layer above)
2-byte Header Checksum
4-byte Source Address
4-byte Destination Address
2.2.3 The transport Layer
The transport layer is responsible for ensuring that all packages are received correctly, in the correct order, and in the correct data. If the package is missing, the transport layer requires the sender to resend the missing package.
There are two protocols for the Transport layer, TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). TCP guarantees that packages are not lost, content and order are correct, and UDP only guarantees that the packets received are correct, regardless of whether a package is missing or the order of packets arrived is correct.
2.2.4 the application Layer
The application layer transmits data to the user. The following three layers together resolve how the data arrives from one computer to another, and the application layer determines how the data is processed when it arrives. Java network programming is mainly in the application layer. Common application layer protocols are: HTTP,SMTP,POP,FTP and so on. Your program can define its own application layer protocol.
Domain Names: The name System (dns:domain name systems) resolves the host name to the Internet address of a number. Java programs use the Java.net.InetAddress class