Linux network programming | TCP programming

 1. Network basics

1.1 History of Internet Development

Internet - a product of the "Cold War"

      In October and November 1957, the former Soviet Union launched two "Sputnik" satellites into the sky.

      In 1958, U.S. President Eisenhower proposed to the U.S. Congress the establishment of DARPA (Defense Advanced Research Project Agency), the Defense Advanced Research Projects Agency, or ARPA for short.

      In June 1968, DARPA proposed "Resource Sharing Computer Networks" with the purpose of interconnecting all DARPA computers. This network was called ARPAnet, or "Arpanet", and was the earliest prototype of the Internet. Contributed to the creation of the TCP/IP protocol

      The early ARPAnet used Network Control Protocol (NCP), which could not interconnect different types of computers and different types of operating systems, and had no error correction function.

      In 1973, Kahn and Vinton Cerf collaborated to develop a new interconnection protocol for ARPAnet.        

      In December 1974, the two officially published the first detailed description of the TCP protocol, but this protocol could not effectively correct when data packets were lost.

        The TCP protocol is divided into two different protocols:

       Transmission Control Protocol TCP used to detect errors in network transmissions

      Internet protocol IP specifically responsible for interconnecting different networks

     Since then, the TCP/IP protocol was born

 1.2 LAN and WAN

(1) Local area network (LAN)

The abbreviation of local area network is LAN, local area network, a local network, which can only realize network communication in a small area and short distance. Our home network is a typical local area network. Computers, mobile phones, TVs, smart speakers, and smart sockets are all connected to the router and can communicate with each other. A local area network is like a road in a community, with many branches and connecting many buildings.

 (2) Wide area network (WAN)

WAN (Wide Area Network) is relative to LAN. The transmission distance of LAN is relatively short and can only be within a small range. If long-distance transmission is required, such as a large enterprise with its headquarters in Beijing and a branch in Changsha, a LAN cannot be set up. A wide area network is like a major road. It may have fewer branches, but it has many types, such as national highways, provincial highways, expressways, trails, etc., connecting many large local area networks.

 advantage:

First, through the Internet, you only need to buy a broadband to achieve communication, which is very convenient, and the current broadband price is relatively cheap.

Second, through the WAN dedicated line. For data security, you cannot connect to the Internet. You need to use your own dedicated line to transmit data. This line only has your own people and no other people will access it. The distance is very long. This network is called a "Wide Area Network".

(3) Light cat 

The optical modem is similar to a digital modem. It is connected to an optical fiber dedicated line and is an optical signal. It is used for the conversion of photoelectric signals and interface protocol conversion in the WAN . The access router is a WAN access. One end is connected to the operator's home cable, usually optical fiber, and the other end is connected to your own router. It is a bridge from the operator to your own device.

(4) Switches and routers 

Switch (data link layer, relying on MAC address): used for data forwarding within the LAN

Router (network layer, requires IP addressing): used to connect the local area network and the external network, and can also forward data

TCP 

TCP (Transmission Control Protocol) is a network transmission protocol located at the transport layer of the OSI model. TCP is a connection-oriented, reliable protocol that ensures data reliability through error-free data transmission and in-order delivery.

TCP communicates by establishing a connection, which consists of a source IP address and port number and a destination IP address and port number. Before establishing a connection, a three-way handshake is required between the client and the server to negotiate communication parameters and confirm each other's status.

Once the connection is established, data can be transferred over the network via TCP. TCP provides mechanisms such as flow control, congestion control, and error checking to ensure that data is not lost, damaged, or out of order during transmission. TCP can also adapt to network congestion and automatically adjust the transmission rate to ensure network stability.

TCP is a byte stream-oriented protocol that divides data into packets for transmission. Each data packet has a sequence number, and the receiver reorganizes the data packets in order according to the sequence number to ensure the accuracy of the data.

In summary, TCP is a reliable, connection-oriented transmission protocol suitable for application scenarios that require reliable data transmission, such as file transfer, email, web browsing, etc.

Guess you like

Origin blog.csdn.net/m0_73731708/article/details/132912888