Computer network

OSI and TCP/IP each layer structure and function, what are the protocols?

1. Application layer (including the application layer + presentation layer + session layer of the seven-layer protocol), whose main task is to complete specific network applications through the interaction of application processes. Defines rules for interaction and communication between application processes. Different applications have different application-layer protocols. The HTTP protocol for the World Wide Web, for example, has port number 80. DNS, the port number is 53. Simple Mail Transfer Protocol SMTP, port number is 25.

2, transport layer, the main task is to provide data transmission services between host processes. It has the characteristics of reuse and reuse. The reuse means that the data of the application layer can be transmitted through the transport layer, and the reuse means that the data received by the transport layer can be delivered to the corresponding application process. TCP and UDP are used at the transport layer

3. The network layer provides communication services for different hosts on the packet switching network. Another task is to select an appropriate route so that packets at the transport layer can find the destination host on the router using routing protocols. Protocols at the network layer include IP, OPSF, and ARP, which can resolve IP addresses into MAC addresses

4. Data link layer. When transmitting at the data link layer, it is always transmitted on a section of a broken link, so it requires specific data link layer protocol to encapsulate IP packets of the network layer into frames and transmit frames on two nodes

5, the physical layer, the transmission unit of the physical layer is bits, the physical layer not only determines how much voltage to represent 1 and 0, but also enables the receiver to parse the received bits.

Three-way handshake

1. First, the client sends a connection request to the server, where SYN bit is 1 and SEQ sequence number is X. At this time, the client does not know whether it and the server can send and receive normally.

2. The server sends a packet segment to the client. SYN is 1 in the same part, ACK is 1, and ACK is 1. At this point, the server knows that the client can send the packet segment and the server can receive the packet segment.

3. When the server sends the message segment, the client knows that it has successfully sent and received the message, and also knows that the server has successfully sent and received the message. The client will confirm the packet segment sent by the server for the third handshake, that is, ACK=1, ACK= y+1. When the server receives the third handshake, it knows that the client can receive it correctly and that it can send the packet segment correctly. At this point the connection is complete.

Why three handshakes

The primary purpose of the three-way handshake is to allow the client and server to establish reliable communication, letting each side know that the other and their own sending and receiving are normal. In fact, four handshakes can be done by splitting the second handshake into two, but this is not necessary.

Why is the SYN returned

A SYN return indicates that this is a segment that accepts a connection.

ACK ACK SYN

In addition to indicating that this is an accepted connection segment, you also need to confirm the segment sent by the client.

What happens when the third handshake fails

If the handshake fails for the third time and times out, the server sends a packet to re-send the handshake for the second time. The default value is five times.

Do you know about SYN attacks? How to prevent?

Syn attacks use TCP defects to send a large number of half-connection requests, consuming CPU and memory resources.

1. Gateway protection

2. Syn cookie defense

SYN cookies modify the three-way handshake on the TCP server to defend against SYN Flood attacks. It works by not allocating a dedicated data area when the TCP server receives a TCP SYN packet and returns a TCP SYN+ACK packet. Instead, it calculates a cookie value based on the SYN packet. Upon receiving a TCP ACK packet, the TCP server checks the VALIDITY of the TCP ACK packet based on the cookie value. If valid, a dedicated data area is reallocated for processing future TCP connections.

Four times to wave

1. The client sends a packet segment in which FIN=1 indicates that it is a connection closing packet (seq=u). At this point, the client is in termination wait phase 1.

2. After receiving the packet, the server returns an ACK=1, ACK= u+1 packet segment, indicating that it has received the request to close the connection. After sending, the server is half closed. After the client receives the packet, the client is in the termination wait phase 2.

3. When no data is transmitted, the server sends a FIN=1 packet with the same id as the second one (SEq = V). The server is in the final confirmation state.

4. After receiving the request to close the connection, the client enters the waiting phase of 2MSL, which is the longest packet segment life.

Four waves is important to the time-wait state, why do you need this state?

1. To ensure that the client can send the last ACK packet to the server, the server times out and resends the FIN packet.

2. To prevent invalid connection request message segments from appearing in this connection.

Why three handshakes and four waves

However, during a handshake, the client does not immediately close the connection. Instead, the client sends a FIN packet after transmitting the resources sent to the client.

The difference between TCP and UDP

The TCP header cost is at least 20 bytes, and the UTP header cost is 8 bytes

TCP transport is reliable, UDP is best delivered

TCP is connection-oriented and UDP is connectionless

TCP is one-to-one, UDP can be one-to-one, one-to-many, many-to-one, one-to-many

TCP is byte stream oriented and UDP is user datagram oriented

How does TCP ensure reliable transmission

1. The application data is divided into the most appropriate data blocks by TCP

2. Stop waiting for an agreement

3. Slide the window to prevent the sender from sending too much.

4. Congestion control

ARQ protocol

Automatic retransmission request. If no acknowledgement packet is received, the device resends the acknowledgement packet after the timeout.

Sliding Windows and flow control

Traffic control is used to control the sending rate of the sender. The size of the receiver’s window can affect the sending rate of the sender.

Congestion control

Congestion control is required when requested resources > available resources

1, slow start, after each transmission round, the value of the congestion window is doubled.

2, congestion avoidance, when the increase to the slow start limit, congestion avoidance.

3. Fast retransmission: as long as one party receives three repeated confirmations in a row, it shall retransmit immediately.

4. Fast recovery. If only individual packets are lost, adjust the threshold to the original general value, and then the window value equals the threshold value.

The process of entering a URL in a browser -> displaying the home page

1. Domain name resolution

2. TCP connection

3. Send the HTTP request

4. Response packets

5. Browser parsing

6. The connection ends

Status code

1. 1XX informational status code

2. 2XX success status code

3. 3XX redirection status code

4. 4XX client error status code

5. 5XX server error status code

The relationship between various protocols and the HTTP protocol

1. TCP establishes the connection

2. HTTP generates request packets and parses them

3. Data is transmitted at the network layer through IP protocol, OPSF routing protocol, and ARP protocol to resolve IP addresses into MAC addresses

HTTP long connection, short connection

An HTTP short connection is a TCP connection that is disconnected after an HTTP operation is completed. A long connection is a connection that is continuously opened for the next time.

HTTP is a protocol that does not save state. How to save user state?

Cookies, session

What does a Cookie do? How is it different from Session?

The function of cookie is to make the stateless HTTP protocol become stateful, because THE HTTP request does not know who sent the data, cookie can carry the data, then know who sent the request, the server can find out who sent the request through the session and find its resources.

Difference between HTTP and HTTPS

HTTPS is the HTTP protocol added on top of SSL/TSL.

Java based

The difference between object-oriented and procedural

The JAVA language has those characteristics

JVMS, JDK, and JRE

The difference between Java and C++

Character constants and string constants

Can the Constructor be Override?

The difference between overwriting and overloading

Object orientation: encapsulation, inheritance, polymorphism.

What is the difference between String, StringBuffer, and StringBuilder?

Automatic packing and unpacking

Why is it illegal to call a non-static method member within a static method?

Define the role of a constructor in Java that does nothing and takes no arguments

The difference between abstract classes and interfaces

The difference between member variables and local variables

The difference between object entities and object references

What are the properties of constructors?

How static methods differ from instance methods

What is the purpose of calling the parent class no-argument constructor before calling the subclass constructor?

== equals(important)

HashCode vs. Equals (Important)

Describes the basic concepts of threads, programs, and processes. And what is the relationship between them?

What states do threads have

Some summary of the final keyword

Exception handling in Java

What if some fields in Java serialization do not want to be serialized

Gets a common method for typing with a keyboard

How many IO streams are there in Java?

What’s the difference between BIO,NIO and AIO?

Deep copy VS shallow copy

How to print the string “test” without using an IDE

(1 time) Talk about the reflex mechanism

(1 times) The difference between arrays and lists

(1 time) Static keyword

The Stream keyword

Java collection

What’s the difference between List,Set and Map?

List: ordered and repeatable Set: unordered and unrepeatable Map: stored in key-value pairs. Keys cannot be repeated and values can be repeated

Is Arraylist different from LinkedList?

ArrayList: The bottom layer is an array, the addresses must be contiguous, the whole array must be moved forward or backward as the deletion increases, but the search only takes O(1) time. LinkedList: the underlying LinkedList is a LinkedList, the addresses are not necessarily contiguous, the performance of deletion increment is better than array, but the search can only be from the root node, that is, O(n) time complexity

How is an ArrayList different from a Vector? Why replace Vector with Arraylist?

Vector is thread-safe, ArrayList is thread-unsafe. ArrayList performs better than Vecor

Expansion mechanism for ArrayList

You start with an empty array, and you expand it when you add data, so if you specify the size of the array when you create an ArrayList, you specify its size if it is larger than ten, and you specify the length of the array if it is smaller than ten. Then the array size is increased by 1.5 times.

Difference between HashMap and Hashtable

HashMap is thread-safe, Hashtable is thread-safe. A hashMap can have a null key, but only one. The value can have more than one NULL. None of the keys in a hashTable can be null

HashMap is different from HashSet

A hashset stores a single value. A HashMap is a key-value pair, and keys cannot be repeated. The underlying hashset is actually the key of the HashMap

How does a HashSet check for repetitions

First, compare hashCode to see if it is the same. If it is different, it is not equal. If it is equal, then call equals.

The underlying implementation of HashMap

Array + linked list/red black tree

Why is the length of a HashMap a power of 2

Hash (array length -1)&hash, which is more efficient than modulo operations

HashMap multithreading causes an infinite loop

When rehash

ConcurrentHashMap and Hashtable

Jdk1.7 uses segmented locking for thread safety. 1.8 The underlying data structure, like hashMap, is array + linked list/red-black tree. However, segmentalized locking is not adopted. The root node is locked, and the concurrency is controlled by synchronized+CAS

ConcurrentHashMap Thread-safe concrete/low-level concrete implementation