1. Principles of application layer protocols
1.1. Architecture of network applications
Possible application architecture:
- Customer-service area model (C/S)
- The unequal model is mainly server-based and has poor scalability.
- Example: web application
- Peer-to-peer model (P2P)
- Self-expandability;
- Example: Thunder
- Hybrid: Client-Server and Peer-to-Peer Architecture
- Napster:
- The host registers its resources on the central server
- The host queries the central server for resource location
- Example: Instant messaging (chat room) :
- Napster:
process communication
Process: An application running on the host
- Form: Access through the services provided by the lower layer of socket API (source language)
- Address: Corresponding SAP at the host level
Addressing : At which address (IP), port
1.2. Socket ( socket )
A process sends a message to a socket or receives a message from a socket
TCP socket: (represents the local IP and port, the other party’s IP and port)
- For applications using connection-oriented services (TCP), a socket is a locally meaningful identifier of a 4-tuple
- 4-tuple: (source IP, source port, destination IP, destination port)
- Uniquely specifies a session (TCP socket actually represents the session relationship between two processes )
- Applications use this flag to communicate with remote application processes
- It is not necessary to specify these 4-tuples in every message sent.
- Just like using the operating system to open a file, the OS returns a file handle, and this file handle will be used later instead of the directory name and file name of the file
- Simple and easy to manage
- So transmitting information only requires passing
- data, socket
UDP socket:
- UDP service, communication between two processes requires no prior connection establishment
- Each message is transmitted independently
- The preceding and following messages are sent to different distributed processes.
- Therefore, only an integer can be used to identify the identifier of this application entity.
- Because this message may be sent to another distributed process
- The minimum size of information passing through an inter-layer interface
- UDP socket: local IP, local port
- But when transmitting a message: you must provide the other party’s IP and port
- When receiving a message: the transport layer needs to upload the IP and port of the other party
- So three things need to be passed to transmit information:
- socket, the data itself, the other party’s address (IP and port)
Performance indicators provided by the transport layer to the application layer:
- Latency, throughput, data loss rate, security
-
Both TCP and UDP are transmitted in clear text and do not provide security.
-
Therefore, if the transmission is secure, the security of the transport layer service needs to be carried out through the SSL protocol.
- The application uses the SSL library, which uses TCP communication
- SSL
- Implemented on TCP to provide encrypted TCP connections
- Privacy
- data integrity
- End-to-end authentication
- SSL socket API
- The application provides an API to pass the plain text to the socket, and SSL encrypts it for transmission over the Internet.
2、WEB and HTTP
Version 1.0 of HTTP is a non-persistent HTTP connection.
After 1.1, the HTTP connection was changed to a persistent HTTP connection;
2.1. HTTP request message: 80 (default port)
- Two types of request messages: request and response;
- HTTP request message:
- ASCII
- Request line (GET, POST)
2.2、FTP:21
ftp: file transfer protocol
Dual-channel connection, performed on two TCP connections, out-of-band (commands sent) and in-band (data sent), stateful protocol
2.3、Email:25
SMTP protocol: mailbox server
- Manage and maintain emails sent to users in the mailbox
- Output message queue holds pending email messages
- SMTP protocol between mail servers
- Send email message
- Client: Sending mail server
- Server: receiving mail server
Three stages of transmission:
- Handshake
- response message
- closure
- SMTP uses persistent connections
- SMTP requires that the message (header and body) be 7 ASCII encoded
- SMTP server uses CRLE, CRLE determines the tail of the message
3、DNS
UDP:57
Domain name resolution system
Problems solved by DNS:
- How to name;
- How to parse;
- How to maintain;
The main ideas of DNS:
- Hierarchical , domain-based naming scheme
- Several distributed databases complete name to IP address conversion
- Application service running on UDP with port 53
- Core Internet functionality, but implemented as application layer protocols
- Handling complexity at the network edge
Main purpose of DNS:
- Implement hostname-IP address conversion (name/IP translate)
- Other purposes
- Host alias to canonical name conversion
- Conversion of mail server alias to mail server's formal name
- load balancing
The general working process of DNS:
- Application calls the resolver
- The parser sends a query message (encapsulated in a UDP segment) to the Name Server as a client.
- Name Server returns response message (name/ip)
- Query domain name method
- recursive query
- Iterative query
- recursive query
4. P2P applications
4.1. Pure P2P architecture
- No (or very few) servers running all the time
4.2. File distribution: C/S vs P2P
- Unstructured P2P
- centralized directory
- Fully distributed
- hybrid
- DHT (Structured) P2P
- Hash table
- tree shape
5. TCP socket programming
5.1. Socket programming
- Application processes use the services provided by the transport layer to exchange messages and implement application protocols to implement applications.
- TCP/IP: The application process uses the Socket API to access the transport protocol
- Where: SAP on the interface (Socket) How: Socket API
- socket: the door between distributed application processes, the end-to-end service interface provided by the transport layer protocol
5.2. TCP socket programming
The server runs first, waiting for the connection to be established
- The server process must be running first
- Create welcome socket
- Bundled with local port
- Blocking wait to receive user connection on welcome socket
The client actively establishes a connection with the server
- Create client local socket (implicitly bound to local port)
- Specify the IP address and port number of the server process to connect to the server process
- When a connection request comes with the client
- The server accepts the request from the client, releases the blocking wait, returns a new socket, and communicates with the client.
- Allows the server to communicate with multiple clients
- Use source IP and source port to differentiate between different clients
- When the connection API call is valid, the client establishes a TCP connection with the server
socket structure
socket interaction
黑色的代表UCP交互的过程,红色的代表应用报文交互的过程
Two processes can guard the same port, but the sockets of the two processes are different.
- The essence of socket is the memory space address of a four-tuple structure.
- The four-tuple represented by socket is target ip/source ip/target port/source port.
UDP Socket Programming
UDP socket exchange, no handshake is required before establishing communication, the connection can be established directly