Internet communication

C/S communication model

C: client client software

(1) The software installed on the client
(2) It is used to request resources from the designated client and ask for files
(3) Help the client software parse the binary data received from the server into text, numbers, videos, pictures, and commands

S: server server software

(1) Software installed on the server
(2) Receive requests from client software
(3) Locate the accessed file
(4) Analyze the located file into binary data

Applicable scenarios:
generally applicable to entertainment (WeChat, QQ, Jingdong, Taobao, B station), large games (Warcraft, lol),

Advantages:
1. Higher security
2. Reduce server pressure (some commands are placed on the client)

Disadvantages:
1. Increase the cost of the client to obtain services (such as some games and other software have configuration requirements)
2. The update is cumbersome

B/S communication model

B: Browser
(1) The browser is software installed on the client
(2) It can send requests to any server
(3) The binary data returned by the server is parsed into pictures, numbers, videos, commands,

S: server client software
(1) software installed on the server
(2) can receive requests sent by any browser
(3) locate the file, convert the file into binary data and return it to the browser

Applicable scenarios: not only suitable for the entertainment market, but also for the daily life of enterprises, with a wider range of applications

Advantages:
1. Will not increase the cost of obtaining services
2. Almost no need to update the browser

Disadvantages:
1. It is almost impossible to protect the resource files of the server (crawler), and the server is "streaking"
2. The working pressure of the server is extremely large [High concurrency solution under B/S]

Sharing resource files under B/S

1. Classification of shared resource files under HTTP:

  • Static resource files (videos, pictures, documents, html, css, js [the latter three can only be compiled and executed in the browser])
  • Dynamic resource file (.class in java)

2. The difference between calling static resource files and dynamic resource files When
static resource files are requested, they are converted into binary and pushed to the browser that initiated the request. When the
dynamic resource files are requested, the http server creates an instance object of the current class and uses the instance object to call the method. Transmit the running result to the browser as binary data through the output stream

3. Under the B/S structure, all network communication information is stored in the http protocol package.
Classification: http request protocol package, http response protocol package

4. The internal space of the http request protocol package:
divided into four spaces from top to bottom

  1. Request line:
    [
    url: request address
    method: request method (GET/POST)
    ]
  2. Request header: request parameter information [GET]
  3. Blank line: no content, isolation effect
  4. Request body: request parameter information [POST]

5. HTTP response protocol package internal space:
divided into four spaces from top to bottom

  1. Status line
    [
    http status code
    ]

  2. Response header
    [
    content-type: specify the browser to use the corresponding compiler to parse the binary data
    ]

  3. Blank line: no content, isolation

  4. Response body
    [
    contents of static resource files that
    may be accessed, commands of static resource files that
    may be accessed, content of dynamic resource files that may be accessed
    (all in binary form)
    ]

Http status code

Status code function:
(1) If the HTTP server returns the relevant resource file, the status code tells the browser how to deal with the result
(2) If the HTTP server does not return the relevant resource file, the status code tells the browser why it cannot provide it

classification:

  • 1xx: The most characteristic 100: Notify the browser that the returned resource file is not an independent resource file
  • 2xx: The most characteristic 200: Inform the browser to return an independent and complete resource file
  • 3xx: The most characteristic 302: Inform the browser to return the address of a resource file
  • 4xx: The most characteristic 404: Notify the browser that the server did not locate the resource file being accessed; 405 mode is not allowed, such as access using get, and only post is implemented in the servlet
  • 5xx: The most characteristic 500 java code throws an exception

Guess you like

Origin blog.csdn.net/weixin_39666736/article/details/107339899