Technology Sharing

network programming!

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

network programming

【1】Network development architecture

(1) C/S architecture
C : client

S: server

APP - the server

The C/S architecture achieves the separation of the front-end interface and the back-end business logic through the interaction between the client software and the server, providing a stable and reliable architecture model.

(2) B/S architecture
B: browser (web page)

S: server

Open QQ Music----> Initiate a request to QQ Music

Render the resources in the local browser

The B/S architecture separates the front-end interface from the back-end business logic through the interaction between the browser and the server, providing a flexible and scalable architecture model.


(3) Advantages and disadvantages of B/S architecture and C/S structure


B / S architecture
Maintenance and upgrades are simple: I only need to update the server resources.

The cost is relatively low and there are many options

There is too much service data and the load is severe

C/S Architecture
The pressure on the server is reduced, and some resources are shared with the client.

Data storage and management are relatively transparent, and APP reverse

High cost and difficult maintenance

C/S architecture is the mainstream trend


【2】Internet Protocol


(1) What is network programming?


The premise of network programming research is based on the Internet

Network programming is writing code based on the Internet

(2) Network programming medium


The medium of network programming is the computer network.

Network protocols, network programming frameworks and libraries are the basis for implementing network programming.

【3】OSI seven-layer protocol


Network communication protocol standards
Application layer: responsible for processing specific application protocols, including email, file transfer, and remote login.

Presentation layer: responsible for the representation and encoding of data, converting and compressing data before transmission in different systems.

Session layer: responsible for establishing, managing, and terminating sessions, including synchronization of data exchange and creation and recovery of checkpoints.

Transport layer: responsible for end-to-end data transmission and providing reliable data transmission services, including flow control, congestion control, error recovery, and data retransmission functions.

Network layer: responsible for implementing data packet forwarding and router selection between different computers, and providing functions such as logical addressing and congestion control.

Data link layer: transmits data through frames and is responsible for reliable data transmission.

Physical layer: responsible for transmitting bit streams on physical media, including transmission media, physical interfaces, and electrical characteristics

advantage:
Easy to understand and implement: Since the OSI model has a clear layered structure, it is easy to understand and implement.

Good scalability: Since this architecture clearly defines different layers and protocols, it has good scalability and new protocols and services can be added at any time.

Improved protocol interoperability: Because the OSI model provides clear guidance for different protocols, it can promote interoperability between devices from different manufacturers and suppliers.

Reduced Complexity: OSI model has less complexity compared to other architectures as the functionality of each layer is fixed.

shortcoming:


Too theoretical: The OSI model is too theoretical, which limits its use in practical implementations.

Lack of flexibility: Since the OSI model defines specific functions at each layer, it lacks flexibility and cannot fully adapt to the requirements of different network environments.

Too complicated: Since the OSI model is divided into 7 layers, it will lead to increased protocol complexity and resource consumption in practical applications.

High implementation cost: Since the OSI model requires the use of a large number of protocols and devices to implement communication between various layers, the implementation cost is very high.

【4】TCP Layer 5 Protocol


Application layer: responsible for handling communications between network applications.

Transport layer: The transport layer protocol provides end-to-end peer protocols to ensure reliable data transmission over the network.

Network layer: handles the transmission and routing of data in the network.

Data Link Layer: Provides reliable data transmission on the physical network. It encapsulates data packets into frames and transmits them through physical media.

Physical layer: responsible for transmitting bit streams on physical media, including transmission media, physical interfaces, and electrical characteristics

advantage:
Simple and clear: The TCP/IP five-layer protocol is simple and clear, easy to understand and implement.

Strong openness: TCP/IP protocol is an open standard with good compatibility and scalability.

Stable and reliable: The TCP protocol provides reliable data transmission services, ensuring data integrity and reliability.

High flexibility: TCP/IP protocol supports a variety of different applications, such as email, file transfer, web browsing, etc.

High security: The TCP/IP protocol provides some security mechanisms, such as IPSec, SSL, etc., to ensure the security and privacy of data.

shortcoming:


High complexity: The implementation of TCP/IP protocol is relatively complex and requires in-depth understanding of the principles of network protocols and related technologies.

Limited performance: In order to ensure data reliability, the TCP protocol will introduce certain delays and overheads, which is not suitable for applications with high real-time requirements.

Insufficient security: Some security mechanisms in the TCP/IP protocol are vulnerable to attacks and additional measures are needed to ensure security.

Limited reliability: Although the TCP/IP protocol provides reliable data transmission services, problems such as packet loss and delay may occur when the network is congested, and some measures need to be taken to solve them.

Not suitable for large-scale deployment: Since the TCP/IP protocol does not take network management and maintenance issues into consideration, some problems may arise in large-scale network deployment.

【5】Ethernet protocol


Standardizes our Internet access standards

It is one of the widespread wired local area network technologies used for data communication in computer networks.

It defines the communication rules and formats of the physical layer and data link layer between computers.

Ethernet ProtocolFeatures
Flexibility, speed, simplicity, reliability, fault tolerance, scalability, reliability

【6】IP protocol


A network communication protocol

The TCP/IP protocol is a network layer protocol that is responsible for transmitting data packets from the source address to the destination address.

It defines how data is transmitted and routed on the Internet.

IP protocolFeatures: No connectivity, simple and flexible, packet transmission, routing selection, IP address, version number, protocol type

【7】Mac address


Network Card

It is also called the physical address, which refers to the globally unique address assigned to network devices (such as computers, routers, switches, network cards) when they are manufactured.

Look for a field called "Physical Address" or "MAC Address"

【8】Broadcast


Data exchange within the same LAN

【9】TCP protocol


Streaming Protocol

Reliable, based on a channel for transmission, the channel is allowed to be established only if it meets the specifications

(1) Three-way handshake


1. The client sends a connection request to the server (with the client's identifier aaa)

2. The server receives the connection request from the client and sends a response to the client (with the server's ID and the client's ID bbb)

3. Establish a connection between the client and the server

(2) Four waves


1. The client sends a disconnect request to the server

2. The server receives the client's request and continues to process the unfinished data

3. Send a disconnect request to the client

4. The client receives the disconnect request from the server and disconnects

【10】UDP protocol


Message Protocol

UDP is a transport layer protocol.

Features
Connectionless: UDP does not require a connection to be established before sending data.

Simple and fast: UDP has a relatively small protocol header and low communication overhead, so the transmission is relatively fast.

Unreliability: UDP does not provide reliability guarantees, and the transmission order of data packets is not guaranteed.

Support broadcast and multicast: all devices connected to the LAN can broadcast

For real-time applications:

【11】Socket protocol is suitable for real-time applications


How to establish a TCP connection / UDP connection

What is a socket:
Scoket can be understood as an abstract endpoint that can be used to establish network connections, send and receive data.

Scocket is a programming interface for network communication, which allows applications to transfer data and classmates between different computers over the network.