About Network Protocol TCP / IP

Knowledge of networking

a) Protocol: tcp, udp, multicast

b) IO (BIO NIO, AIO)

c) Socket

d) NINE (Netty / My)

e) serialization and deserialization

A http request, process the request throughout the network

When an application using TCP to transfer data, the data is sent to the protocol stack, through each layer then one by one until it is fed into the network as a series of bit streams. Wherein each layer of the data received must add some header information

When the destination host receives an Ethernet data frame, the data from the protocol stack begins to increase, at the same time remove the packet header plus the protocol layers from substrates. Cassette have to check each protocol packet protocol identification in the header to determine the upper layer protocol of the received data. This process is called demultiplexing

Why have to go MAC layer IP layer it?

mac address is just like a personal ID number, ID number and city people who account where, date of birth about, but the people and the location where it does not matter, people will move, knowing a person's ID number, and the person can not find it, similar to the mac address, which is associated with producers and equipment, batch, date and the like and, knowing mac a device, and it will not send data to the network, unless it is transmitted and parties within the same network. So to enable communication between machines, but also the concept of ip address, ip address is the expression of the current machine in the network, similar to the way the city name + number + concept house number. By addressing ip layer, we can know the transmission of data between machines on a path by which any two of the Internet around the world.

Focus on understanding of the IP protocol and TCP / UDP protocol

What is the protocol

The equivalent of two agreements reached by the agreed need for a network communications program, which defines the meaning and message exchange included. For example (HTTP) to resolve the problem hypertext transfer objects between servers, these hypertext objects are created and stored in the server by the Web browser to visualize complete user perception and experience of remote content

What is the IP protocol

TCP and UDP are the two most well-known transport layer protocol they are using IP as the network layer protocol. IP protocol provides a set of packet data services, the text in each packet is handled independently by the network and distribution, as express parcels sent, like, in order to achieve this, each IP packet must contain a destination address field ; we just need to specify the courier to send the recipient information, and we send it express the same, there could be wrapped loss problem, so the IP protocol is only a "best effort" protocol, the network transfer may, packet loss, packet scramble, the situation is repeatedly transmitted. Transport protocol layers above the IP layer, provides two selectable protocol, TCP, UPD. Both protocols are built on the basis of services provided by the IP layer, selection of transmission in different ways according to the different needs of the application;

## TCP/IP

TCP is designed to detect and recover from the host to the IP layer provides a host of communication messages that may occur lost, duplicate and other errors. TCP provides a reliable byte stream channel, so that applications do not need to consider these issues. Meanwhile, TCP protocol is a connection-oriented protocol, prior to communicate using TCP, it is necessary to establish a TCP connection between two applications, and this in turn is connected to two computers involves the exchange of messages required to complete the handshake.

UDP/IP

UDP protocol error will not be generated by the IP layer restoration, but simply extends the IP protocol "best effort" data packet services, enabling him to work between applications, instead of between hosts, Therefore, using the UDP protocol must take into account packet loss, out of order problem

How do TCP is a reliable transport?

Establish a reliable link

Due to TCP protocol is a credible transfer protocol, so before transmission, need to pass three-way handshake to establish a connection, the so-called three-way handshake TCP connection is established, the client and the server needs to send a total of three packages to confirm establishing a connection

Four waving protocol TCP

Four waving indicate when TCP disconnected, the client and the server needs to send a total of four packages to confirm the connection is disconnected; the client or the server can initiate wave action (because TCP is a full-duplex protocol), in socket programming, either performing close () operation to produce hand-waving operation.

tips: Why is the time of connection is three-way handshake, when it is closed handshake?

Because when the three-way handshake is because Client Server side terminal receives a connection request SYN packet, it can be sent directly SYN + ACK packet. Wherein the ACK message is used for response, SYN etc is used to synchronize the packet. But the connection is closed, when the Server side FIN packet is received, probably does not close SOCKET immediately (because there may be a message not processed), we can only respond to a first ACK packet, told Client-side, "you issued FIN message I received. " Only until the end of all my Server messages are sent over, I can send FIN packets, and therefore can not be sent together. It requires a four-step handshake.

Acknowledgments and flow control data transmission process

After establishing a reliable connection, the data transmission begins. In the communication process, the most important is a data packet, i.e. the data transfer protocol. If this occurs too busy to receive debit among data transmission and reception process, then it is necessary to control the sender in order to avoid loss of data. Using a sliding window mechanism can easily achieve traffic control at the sender TCP connection. TCP window in bytes, not the segment, the sender the transmission window can not exceed the value of the receiving window of the receiver are given.

Sliding window protocol

Sliding window (Sliding window) is a flow control technique. Early in a communication network, the communication network congestion does not consider the two sides of the transmission data directly. Because we do not know the network congestion status, send data, resulting in an intermediate node blocks substitution, who also can not send data, so there is a sliding window mechanism to address this problem; sending and receiving party will maintain a data frame sequence, this sequence It is called the window

Simple explanation, the transmission and receiver are maintained for a sequence of data frames, this sequence is referred to as a window. Sender window size is determined by the recipient, the purpose of controlling the transmission speed, so the recipient is not large enough cache, resulting in an overflow while controlling the flow of network congestion is avoided. The following figures 4,5,6 the data frame has been sent, but not received ACK associated 7,8,9 frames are waiting to be sent. It can be seen as a window size of the transmitting end 6, which is informed by the receiving end. At this time, if the sender receives No. 4 ACK, the contraction of the left edge of the window to the right, the right edge of the window is extended to the right, then the forward window is "slid", i.e., the data frame 10 may also be transmitted.

Send window

Continuously transmitting side is transmitted to allow frame number table. The transmit end can not wait for a response maximum number of frames transmitted continuously referred to as the send window size.

Receive Window

Table No. allow the recipient received frame, where the frame falls within the receiver window, the receiver must process the received frame to fall outside the window are discarded. Allowing each recipient received frames known as size of the receive window.

Online presentation capabilities sliding window

Performance issues? Communication

Normal communication process is as follows (BIO)

We found that TCP response from the server can only handle a client request, when a client sends a connection request to the server has been occupied by other clients, although you can send data to the server when the connection is established, but the processing on the server side prior to completion of previous requests, the new client will not have to respond to this type of server is called "iteration server." Iterative server is processing client requests in the order, that is, before the server must finish processing a request to respond to the request the next client. In practice, however, we can not receive such treatment. So we need a way can be processed independently of each connection, and they will not interfere with each other. The multi-threaded Java technology provides just over

Guess you like

Origin www.cnblogs.com/nangonghui/p/12008954.html