In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
I. Overview of HTTP
HTTP is the abbreviation of HyperText Transfer Protocol, that is, Hypertext transfer Protocol. HTTP is an application layer protocol, which, like other application layer protocols, is designed to implement a certain kind of specific application protocol, and its function is realized by an application program running in the user space. HTTP is a protocol specification, which is documented and is the implementation of HTTP that really communicates through the HTTP protocol. We know that the HTTP protocol communicates based on the Cramp S architecture, while the server-side implementation programs of the HTTP protocol include httpd, nginx, etc., and the client-side implementation programs are mainly Web browsers, such as Firefox, Internet Explorer, Google chrome, Safari, Opera, etc., in addition, the client command-line tools include elink, crul and so on. Web services are based on TCP, so in order to be able to respond to client requests at any time, the Web server needs to listen on the 80/TCP port. The client browser and the Web server can communicate through the HTTP protocol.
II. Ports defined by IANA
We know that Web servers usually need to listen on port 80 in order for all client browser programs to communicate with them. When a user types URL on a browser, for example: www.baidu.com, the default port is 80. This port is specified by the IANA (Internet Assigned Numbers Authority) assignment. In addition, IANA is managed by ICANN, which defines the following ports:
① 0-1023: a well-known port that is permanently assigned to fixed applications. The use of these ports requires registration by specific applications and belongs to privileged ports, such as Web service 80mp TCP 21/tcp and so on. Only the system administrator has permission to enable this type of port and allow the process to listen, while ordinary users do not have permission.
② 1024-41951: also registered ports, but the requirements are not particularly strict, these ports are assigned to programs and registered for use by certain applications, but these applications are not very common, such as mysql service 3306max TCPMagemcache 11211/tcp and so on.
③ 41952 ports: the ports randomly used by client programs are dynamic ports or private ports. On Linux, this type of port range is defined in / proc/sys/net/ipv4/ip_local_port_range.
III. BSD Socket
BSD Socket is the earliest process communication mechanism of BSD Unix system. Socket is a socket, as an implementation of IPC (Inter-Process Communication), which allows inter-process communication mechanisms on different hosts (or on the same host). Socket can be understood as a "socket", as long as the wire is plugged into this "socket", you can communicate. In essence, Socket should be Socket API, which encapsulates the communication details related to socket communication in the kernel, that is, it encapsulates the specific communication details to be implemented in the communication subnet (transport layer, network layer, data link layer, physical layer). Programmers can write programs that can realize network communication by calling Socket API.
Socket describes the IP address and port. Different services have different port numbers. Each service needs to bind and listen on a port and open a Socket, while the client can establish a connection with the Socket on the server through a Socket, so that the two can communicate. We call a pair of sockets that are in communication state connected sockets. Generally speaking, Socket is the bridge between the application layer and the transport layer, as shown in the figure.
As mentioned earlier, Socket is a description of IP address and port number, and an IP address plus a port is a socket. According to the protocols used by Socket at the transport layer, it can be divided into the following three categories:
(1) SOCK_STREAM:tcp socket
(2) SOCK_DGRAM:udp socket
(3) SOCK_RAW:raw socket
The raw socket here refers to a way to communicate directly by sending or receiving IP packets without using any transport layer protocols (such as tcp, udp, etc.), that is, the application layer directly bypasses protocols such as tcp/udp and communicates directly based on IP packets.
According to the address format of Socket snooping, Socket Domain can be divided into:
(1) AF_INET:Address Family,IPv4 address format
(2) AF_INET6:Address Family,IPv6 address format
(3) AF_UNIX:Address Family, an address format used for communication between different processes on the same host based on Socket sockets, which is represented by a socket file (Linux everything file); this address is also called Unix_SOCK.
Next, we will show how the TCP client and server communicate through the TCP socket interface. As shown in the picture.
For the TCP server, first you need to call the socket () function to register with the kernel to create a TCP socket (IP address + port). Once the application is successful, you need to bind the bind () function to the socket. After binding, you need to call the listen () function to make the server process listen on the socket and allow the socket to connect, but you cannot receive user requests at this time. It is only after the accept () function is called that it is responsible for receiving the client request and remains blocked until the client request arrives, when the state of the TCP server process is LISTEN.
For the TCP client, the socket () function also needs to be called to create the socket, but there is no need to listen; when the client initiates a connection request to the server, the connect () function is called, where the parameters in parentheses include the IP address and port of the other server If the server receives the connection request, the two sides carry out the tcp three-way handshake to establish a two-way virtual link, when the socket between the client and the server is in the connected state (ESTABLISHED), and the subsequent http request / response messages are sent based on the previously established virtual link.
On Linux, after the connection is established, the client can fill in the requested data on the socket file that establishes the connection with the server, and writing the data is equivalent to sending data to the server. This process is accomplished by calling the write () function. On the other hand, the server can read the data on the socket file that connects with the client, that is, call the read () function, which is equivalent to receiving the data requested by the client. The specific communication details between the two are completed by the underlying communication subnet. After the server reads the request message sent by the client, it parses the request, processes the request and constructs the response message, then writes the response message into the socket file by calling the write () function, and transmits it to the socket file of the client through the communication subnet, and the client can get the response message of the server through this socket file. This cycle goes back and forth several times until the client requests to disconnect (usually the client actively requests disconnection, but when using the keep-alive connection mode, the server may actively request disconnection).
Once the client requests a disconnect, the TCP server agrees to disconnect by calling the read () function to read the disconnect request data in the socket file.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.