Five Java related questions per day (5)--mainly on network protocol (emphasis)

Source: Internet
Author: User
Tags file transfer protocol

Today is mainly the network thread, the content is a bit more slowly remember ... But it is a very important point of knowledge in the interview. So we need to remember and understand.

1.OSI seven-layer model, function for each layer (OSI Open System interface)

For:

Physical layer: The main definition of physical equipment standards, such as the interface type of network cable, the interface type of optical fiber, the transmission rate of various transmission media. Its main role is to transmit the bitstream (that is, 1, 0 is converted to the current strength to carry out the transmission, after reaching the destination in the conversion to 1, 0, that is, we often say the digital-to-analog conversion and A/D conversion). This layer of data is called a bit.

Data Link Layer: defines how to make data formatted for transmission and how to control access to physical media. This layer also often provides error detection and correction to ensure reliable data transmission.

Network layer: provides connectivity and path selection between two host systems located in geographically diverse networks.

Transport Layer: defines protocols and port numbers for transmitting data (WWW port 80, etc.)

-Data transfer Service (4 above) (3 below) for end users-

Session Layer: A path for data transmission through the Transport Layer (port number: Transport port and receive port)

Presentation layer: ensures that the information sent by the application layer of one system can be read by the application layer of another system.

Application layer: is the OSI layer closest to the user. This layer provides network services for user applications such as e-mail, file transfer, and terminal emulation.

2. TCP/IP four-layer model, function of each layer


is corresponding to the content of the OSI layer.
host-to-network layer: In fact, the TCP/IP reference model does not really describe the implementation of this layer, it only requires the ability to provide a provider to its upper-network interconnect layer, in order to pass IP packets on it. Because this level is not defined, its specific implementation will vary depending on the type of network.

Network interconnect Layer: defines the grouping format and protocol, the IP protocol (Internet Protocol). In addition to the ability to complete routing, the network interconnect layer can also accomplish the tasks of interconnecting different types of networks (heterogeneous networks). In addition, the network interconnect layer also needs to complete the congestion control function.

Transport Layer: in the TCP/IP model, the function of the transport layer is to enable the peer entities on the source and destination hosts to have sessions. Two protocols with different quality of service are defined at the transport layer. That is, TCP (Transmission Control Protocol) and Subscriber Datagram Protocol UDP (User Datagram Protocol).

Application Layer (Session layer, presentation layer, Application layer): The TCP/IP model merges the functionality of the session and presentation layers in the OSI reference model into an application-level implementation.
Application level introduces different application layer protocols to different network applications. Among them, there are TCP protocol-based, such as File Transfer Protocol (Transfer PROTOCOL,FTP), Virtual Terminal Protocol (TELNET), Hypertext link Protocol (Hyper text Transfer protocol,http), There are also UDP-based protocols.

3. What is the IP protocol, the IPV4 package structure, and the meaning of each data field in the structure?

For:
IP protocol: Used to connect multiple packet-switched networks, which transmits a kind of thing called a packet between the source address and the destination address, it also provides the ability to reassemble the data size to suit the packet size requirements of different networks.

version Number (VERS): 4 bits, which represents the IP protocol version number. The current version number is 4, which is IPv4. The version number specifies the format of the datagram. Versions differ in their datagram formats, such as IPV6 's message structure, which differs from the IPV4 structure.

message header Length (Hlen): 4 bits, indicating the length of the message header. The message header length is calculated in 4 byte units. Other fields must exist except for the IP options (IP option) and the Fill (Padding) fields, which may not exist. The fields that must exist are 5 4 byte, which is a total of three bytes long. Therefore, the message header length value is generally 5. And since the message header length must be an integer multiple of 32 bits, when an IP datagram containing an IP option field is not an integer multiple of 32 bits, the Fill field is filled with 0.

service type (type of services): The TOS field, 8 bits, indicates how this datagram is handled. It is mainly used to indicate the priority of the datagram and the type of transmission. QoS technology is the use of this field to mark the priority of the data.

* * Total length: **16 bits, in bytes, representing the entire IP datagram length, including the packet header and the data it carries. Because the total Length field is 16 bits, the IP datagram can be up to 216 1=65 535 bytes long.

Identification (identification): 16 bits, which is the identifier given to the datagram by the sender, and the recipient uses this information and source address to determine which datagram the packet is received for reorganization. Therefore, at the time of the Shard, the domain must be copied without modification to the headers of each shard.

Flag (Flags): 3 bits, only low two bits are valid. A first bit of 0 indicates that the Shard is the last piece, if the bit is 1, then there are shards behind it. A second bit of 0 indicates that the datagram can be fragmented if the bit is 1 to indicate that the datagram cannot be fragmented. When the bit is set to 1 and the frame length does not match and must be fragmented, the device discards the datagram and returns an error message.

Slice offset (Fragment offset): indicates the offset of this shard data in the initial datagram data area, which is offset in 8 byte, and the Shard order is provided by the slice offset at the time of reorganization.

time to Live: short ttl,8 bit, which controls the time that datagrams exist on the network. The current TTL value does not represent time, but rather represents the number of passes through the router. Each time the datagram passes through a router, the router decrements the TTL value by 1, and once ttl=0, the system discards the datagram and returns an error message. This avoids an endless loop of datagrams between routers when routing loops occur.

Protocol (PROTOCOL): 8 bits, which indicates which upper layer protocol the data is carrying, which is the protocol type that indicates the transport layer. As the most common protocol type is TCP or UDP.

Header Checksum (header Checksum): 16 bits to ensure the integrity of the IP header data.

Address: divided into the source IP address and destination IP address, each accounted for 32 bits, indicating the source of the data and the destination of its arrival.

padding (Padding): when the IP header length is not an integer multiple of 32 bits, the fill of the zeros is rounded up to 32-bit integer multiples, with no practical significance.

Data: data segments from the 4th tier.

4. What is the TCP protocol? TCP packet Structure? TCP establishes a join of three handshake, disconnects four waves of the process?

For:
TCP: TCP (transmission Control Protocol, transmission Protocol) is a connection-based protocol, which means that a reliable connection must be established with each other before the data is formally sent and received.

Packet structure:

three-time handshake the image says: Let's take a look at the simple process of three conversations: Host A sends a connection request packet to Host B: "I want to send you data, OK?" "This is the first conversation; Host B sends a consent connection to host A and requires synchronization (synchronization is the two host one in the send, one in the receiving, coordination work) packet:" Can, when do you send? " "This is the second conversation; Host a then sends a packet to confirm that Host B's requirements are synchronized:" I'll send it now, you go on! " ", this is the third dialogue. Three times the purpose of the "conversation" is to synchronize the sending and receiving of packets, and after three "conversations", host a formally sends the data to Host B.

Four times wave:

5. What are the 7 steps experienced by a complete HTTP request?

For:
The HTTP communication mechanism is that during a complete HTTP communication, the following 7 steps will be completed between the Web browser and the Web server:

    • Establish a TCP connection
      Before HTTP work begins, the Web browser first establishes a connection to the Web server over the network, which is done through TCP, which works with the IP protocol to build the Internet, known as the TCP/IP protocol family, so the internet is also known as a TCP/IP network. HTTP is a higher level of application-level protocol than TCP, according to the rules, only the lower layer protocol is established before a higher-level protocol connection, therefore, the first to establish a TCP connection, the port number of the general TCP connection is 80.
    • Web browser sends request command to Web server
      Once a TCP connection is established, the Web browser sends a request command to the Web server. For example: get/sample/hello.jsp http/1.1.
    • Web browser sends request header information
      After the browser sends its request command, it also sends some other information to the Web server in the form of header information, and then the browser sends a blank line to notify the server that it has ended sending the header information.
    • Web server Answer
      After the client makes a request to the server, the server responds back to the client, http/1.1, and the first part of the answer is the version number of the protocol and the response status code.
    • Web server sends answer header information
      Just as the client sends information about itself along with the request, the server also sends the user with the answer about its own data and the requested document.
    • Web server sends data to browser
      After the Web server sends the header information to the browser, it sends a blank line to indicate that the header information is sent to the end, and then it sends the actual data requested by the user in the format described in the Content-type reply header information.
    • Web server shuts down TCP connection
      In general, once the Web server sends the request data to the browser, it closes the TCP connection and then if the browser or server joins this line of code in its header: connection:keep-alive
      The TCP connection remains open after it is sent, so the browser can continue to send requests through the same connection. Maintaining a connection saves the time it takes to establish a new connection for each request and also saves network bandwidth.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Please give me a lot of advice ~

Five Java related questions per day (5)--Main about network protocol (emphasis)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.