Network Programming-basic and communication elements, network programming communication elements
Basic network knowledge
Computer Network: Connects computers distributed in different geographic regions with dedicated external devices using communication lines into a large and functional network system. So that many computers can easily transmit information to each other and share hardware, software, data information, and other resources.
Network Architecture:
① The Network Architecture defines how computer devices and other devices are connected together to form a communication system that allows users to share information and resources.
② In 1978, ISO proposed the "Open System Interconnection Reference Model ". The famous OSI model. The OSI model ensures product compatibility among various equipment manufacturers.
③ This model divides computer networks into seven layers: physical layer, data link layer, network layer, transmission layer, Session Layer, presentation layer, and application layer.
Application Layer |
7 |
Provides inter-Application Communication |
Presentation Layer |
6 |
Processing data formats, data encryption, etc. |
Session Layer |
5 |
Establish, maintain, and manage sessions |
Transport Layer |
4 |
Establish Host end-to-end connection |
Network Layer |
3 |
Addressing and Route Selection |
Data Link Layer |
2 |
Provides media access and link management. |
Physical Layer |
1 |
Bit stream transmission |
Advantages of OSI Model Hierarchy
① Devices produced by different manufacturers can be compatible with each other.
② The device can focus on the functions of a certain layer. For example, the switch works on the second layer, and the router works on the third layer.
③ Facilitate troubleshooting of network faults.
④ You don't have to worry too much about physical interfaces and other physical layer things.
Data encapsulation process in OSI reference model
TCP/IPIs a set of communication protocols used to achieve network interconnection. The Internet architecture is centered on TCP/IP. The TCP/IP-based reference model divides the protocols into four layers: network interface layer, network layer, transport layer, and application layer.
Objective of Network Programming: Communication with other computers directly or indirectly through network protocols. There are two main problems in network programming: How to accurately locate one or more hosts on the network, and how to transmit data reliably and efficiently after finding the hosts.
Network communication elements: IP address, port number, and transmission protocol.
IP address
① Each host on the network must have a unique IP address.
② IP addresses on the Internet are globally unique.
③ The IP address consists of 32-bit binary values, which are 4 bytes in decimal format, for example, 192.168.0.5.
④ Corresponding class-InetAddress.
Port Number
① The port number indicates the application on the computer and the logical address of the application.
② The port number is represented by a 16-digit number, and its range is 0 ~ The port numbers below 65535,1024 are reserved for the predefined service. For example, http uses port 80.
Protocol Concept
A set of rules, standards, or conventions established for data exchange in a computer network.
Common transmission protocols
① TCP: a connection-oriented protocol for reliable transmission. It is transmitted over TCP to obtain a sequential error-free data stream.
② UDP: a connectionless protocol. Each datagram is an independent information, including the complete source address or destination address. It is transmitted to the destination in any possible path on the network, therefore, whether or not to reach the destination, the time to arrive at the destination, and the correctness of the content cannot be guaranteed.