1. Communication model between client and server
A model diagram of the communication between the client and server based on the socket connection, as shown, the entire communication process is as follows:
(1) The server-side starts the listener first, listens to the specified port, waits for the connection request of the receiving client;
(2) The client program starts, requests the connection server the designated port;
(3) The server receives a connection request from the client and establishes a socket (socket) connection with the client;
(4) After the successful connection, the client and the server open two streams, where the client's input to the server side of the output stream, the server's input to connect to the client's output stream, both sides of the flow connected successfully after two-way communication can be done.
(5) When the communication is complete, the client and the server side are disconnected on each side.
NOTE: socket (socket): is a mutual communication between the computer's two-way port, including the host's IP address, service type, TCP/IP protocol port. Among them, the TCP/IP protocol port is the identification information describing the process of sending and receiving network communication, specifically to provide a place for the legend of information. When an application is bound to a port, the operating system sends the received data to the port-specified application process. Each port has an identifier for the number of port numbers to use to differentiate between different ports. The port number can be any number between 0~65535.
The port number of the 0~255 is the reserved port of the system, which is used for communication of system process;
The other ports are free ports that can be used freely for the process;
Defined port number: The default communication port for the TOMCAT server is 8080;
The MySQL default communication port is 3306;
The default communication port for SQL Server is 1433;
2. Communication model between browser and server (b/s)
From the above 1, we can see that the communication mode of C/s is using the socket to achieve, and b/s communication mode is using HTTP to achieve. The HTTP (Hypertext Transfer Protocol) Hypertext Transfer Protocol is a rule that specifies the communication between the browser and the World Wide Web server.
The communication between the browser and the server is a complete HTTP communication process, including the following 7 steps:
(1) establishing a TCP connection;
(2) The browser sends a request command (i.e. HTTP request) to the server;
(3) The browser sends the request header information;
(4) Server Response (HTTP response);
(5) The server sends the reply header information
(6) The server sends data to the browser
(7) The server shuts down the TCP connection
Note: HTTP request and response format, see URL: http://www.cnblogs.com/shaoge/archive/2009/08/14/1546019.html
HTTP response code (that is, "not fonud Error 505" Type information is sometimes displayed when we browse a Web page), as follows:
1xx--Information Class (information): Indicates receipt of the browser request, is further processing;
2xx--Success Class (successful): Indicates that the user request is received, understood and processed correctly;
3xx--redirect Class (redirection): Indicates that the request has not been successful and the customer must take further action;
4xx--Client Error: Indicates that the request submitted by the client is wrong;
5xx--Server Error: Indicates that the server could not complete processing of the request.
C/s communication model and B/s communication model introduction