unix network programming a preliminary understanding of TCP / IP protocol

1. URL (URL, uniform resource locator Uniform Resource Locator)

Elements of the URL: http :( mechanism for representing the beginning of the data source, that is the agreement) + // (behind the string representation of the name of the server) + web server name + " / (directory name) + / (filename) " ( represents the path name of the data source)

Examples: http: //www.lab.glasscom.com/dirl1/file1.html

URL file name can be omitted in most cases are index.html or default.htm

2. File Transfer Protocol (FTP, file transfer protocol)

FTP protocol for use at the time of upload and download FTP files.

3.DNS (domain name system, domain name service system)

  1. Function: ip address and the server name is associated.
  2. Composition: by domain name resolvers and domain name servers.

About Domain Name Server : the domain name and corresponding domain name server to save the ip address of the network, but also with the domain name into an ip address function.

(Each domain has a corresponding ip address, ip address but does not necessarily have a domain name.)

Domain Name Server is a client / server mode, the server side, it is mainly in two forms: primary and redirect servers .

  • DNS is how to work? The distribution of information stored in multiple DNS servers, the DNS server cooperate with each other in order to find the information query.
  • How to register and save on the DNS server? All information DNS domain name servers are in accordance with hierarchical structure to hold

4. Domain Name

Are usually the domain with a period (.) Names separated.

The domain of each period represents the amount of the boundaries between the different levels.

In the domain name, the right location, the higher their level. For example www.baidu.com. The domain name, the next layer is baidu com domain of the domain, and then the next layer is the www domain.

5. Server 

Configuration server including a processor , a hard disk , memory , system bus, etc., and general computer architecture similar

However, due to the need to provide highly reliable services, in terms of processing power, stability, reliability, security, scalability, manageability, and so demanding.

In the network environment, according to the type of service provided by the server , divided into a file server , database server , application server, the WEB server and so on.

According server grade (network size, overall server performance) divided into entry-level servers, workgroup servers, departmental servers, enterprise servers, video servers.

Server's operating system: WINDOWS, NetWare, Unix, Linux

6. "/" Root directory

Root directory is the top-most level "root directory." In fact, "/" itself has no name, we just "/" to represent it.

The basic idea of ​​7.HTTP

  • First, the client sends a request message to the server, including "what (URL)" and "how to carry out the process (method)"
  • Secondly, the server operates in accordance with the requirements of customers, the results after the completion of the response message on the inside.
  • Finally, a response message back to the client, the client after receiving the message, the browser reads the required content is displayed.

Basic knowledge 8.IP address

By a number of smaller sub-networks based router connected together to form a large network (super-network).

We router in reality usually include hubs and routers in two parts.

  1. What is a subnet? Subnets can be understood as a few computers connected by hubs, as a unit, a subnet.
  2. What is a network? The sub-networks into a network with a router.
  3. What is a router? Kind of packet forwarding apparatus (which means data packet, since the data is transmitted in packets)
  4. What is a hub? Kind of packet forwarding devices, and the hub is divided into a relay switching hub two kinds.
  5. What is an IP address? IP addresses can be seen as "...... No ...... room." "Number" corresponding to the network number , "room" corresponding to the host number , the whole of the address called an IP address .

Specific IP address 32 bit, 8 th 'bit (a byte byte) is divided into a set of 4 groups.

Network number and host number to link a total of 32bit, but these two parts is not fixed.

9. Subnet mask (the subnet mask involves a lot of content)

The role of the subnet mask: The IP address is divided into a network address and host address in two parts. (?) And can show the relationship between subnets where a host of other subnets.

  • Class A default subnet mask address is 255.0.0.0
  • Class B subnet mask, the default address is 255.255.0.0
  • The default subnet mask is 255.255.255.0 Class C address

The subnet mask can use a large network into subnets that VLSM (Variable Length Subnet Mask), you can put small networks merge into a large network that is super-network .

Subnet mask setting rules:

Subnet mask length of 32 bits, the left is the network bit, "1" is represented by a binary number 1 is equal to the length of the web site; the right position is the host, binary "0", the host position is equal to the number 0 length.

Objective: To make a mask with the ip address bit to do to determine the number of hosts subnets through the digits 0 and 0 when the operation covered by the original hosts, without changing the digital network segment, and very easy. (?)

? How to determine a different computer on the same subnet:

Found ip address and subnet mask of the computer, the post-decimal to binary AND operation is then converted to decimal. If the result is the same, then we can think of several computers on the same subnet.

10. The delegate stack transmits information

Operation of transmitting and receiving data broadly divided into four processes:

  1. Create a socket (socket creation stage)
  2. To a terminal connected to a pipe socket (connection phase)
  3. Data transceiver (communication phase)
  4. Disconnect and remove the pipe socket (off stage)

Socket concept: that the key to creating data entry conduit pipe ends, the entrance became socket.

  • Descriptor: The application of the mechanism used to identify a socket          
  • IP address and port number: used to identify the other socket mechanism between client and server

 11. Create a socket

Create a socket of the process: The application calls socket to create a socket application, protocol stack creation sockets on the application of execution of the application.

When creating the socket, a socket is first allocated memory space required, and to write to the initial state.

Browser, mail and other general applications send and receive data using TCP time.

When the DNS query using UDP shorter control data transceiver.

The relationship between the protocol stack and sockets: the protocol stack is based on the control information recorded in the socket to work.

12. NIC

PC card is working in the link layer network component is an interface to connect the computer and the LAN transmission medium. Can be achieved not only between the LAN transmission medium physically connected and telecommunications numbers match, but also relates to transmission and reception, the encapsulation and decapsulation frame, media access control, and data encoding and decoding functions of the frame buffer data.

Due to the data rate and the data rate on the bus is not the same computer on the network, so there are still card data cache memory chips.

Card functions: serial / parallel conversion

  • Communication between the card and a local area network: for the serial transmission via cable or twisted-pair
  • Communication between the card and the computer: O bus for the computer's motherboard through I / parallel transmission conducted.

 13. Stack

Protocol stack (Protocol Stack) is the sum of the network protocol layers, which reflects the image of the network during a file transfer: from the upper layer protocol to the underlying protocol, then the protocol from the bottom to the upper layer protocol. Protocol stack in the operating system.

Is the most widely used Internet protocol stack, from top to bottom are the agreement

  • Application layer (HTTP, FTP, TFTP, TELNET, DNS, EMAIL, etc.)
  • Transport layer (TCP, UDP), the network layer (IP)
  • Link layer (WI-FI, Ethernet, Token Ring, FDDI, MAC, etc.)
  • Physical Layer

DETAILED exchange process between the protocol stack and application: during the reception of data, the protocol stack will check the received data blocks and the contents of the TCP header, no data is lost if the return ADK number. Then the protocol stack blocks of data temporarily stored in the receive buffer, and the data block in order to restore the original data are connected, and finally to the application data. Specifically, the protocol stack of copy data to the memory address specified by the application, and then return control to the application flow.

14. responsible for keeping control of header information

Type head: TCP header, Ethernet header (MAC header), IP head

Action of the head: recording and exchange control information. 

Storing configuration data packet :( order from left to right) control information, the control information of the Ethernet and IP --TCP of - data block

Control packet constituting the only information left to right order :() Ethernet and IP control information of --TCP

Control information used for communication operations fall into two categories:

  • Record information in the header
  • Socket (protocol stack memory space) of the information recorded in

 15. The connection phase (the pipe socket connected to a terminal)

The first step is to create a join operation in the TCP header indicating the source module connected to the operation information.

In the TCP header by the sender and the receiver can find the port number of a socket connection.

After creating a socket, the application calls the Connect , then socket protocol stack will be the local socket to connect to the server.

16. The data transceiver (communication phase)

Send and receive data write operation is a call to be sent from the application data to the start of the protocol stack.

After performing the protocol stack receives the data transmission operation:

1. Stack will only focus on the application of data sent over the length. After the protocol stack is not necessarily received data is sent immediately, store it put data into the internal buffer in, and wait for the next piece of data applications.

In the end when to send it, stack it still has to determine the criteria:

MTU: Maximum length of a packet network, Ethernet is typically 1500 bytes.

MSS: After removing the header, a packet network can accommodate the maximum length of the TCP data.

2. If the data is large, the data transmission in the cache is split in units of length MSS split out of each data will be placed in a separate packet network. After the split, when it is determined that data needs to be sent, will be in front of each data plus a TCP header, and based on the control information marks sender and the receiver port number recorded in the socket, and then to the IP module performs an operation of transmitting data.

3, how to determine the network packet has been received it? Determining the ACK number received packet network

The "number" and "ACK number" can confirm whether the receiver receives the network packet. (This is a two-way interaction mechanisms) 

Receiving a HTTP response message 17

The browser returns a response message to the web server, you need to call read program to get the response message. Control will be transferred to the stack by the read, and the protocol stack performs subsequent operations.

18. The socket connector is disconnected from the server

When one is finished sending data initiates the disconnection process.

(Hereinafter to server as an example)

  • The server side of the application program calls the Socket library close
  • Server protocol stack will generate TCP header contains information off
  • Commissioned IP protocol stack module sends data to the client, while the disconnection operation of the message server socket records.

(Hereinafter a client, for example)

  • Receive TCP header sent from the server, the client protocol stack will own socket Commission for Discipline Inspection off into the operating state
  • The client will return a number ACK to the server to inform the server has received the TCP header. Stack will wait for the application to fetch data.
  • Applications will call read to read the data.
  • The client invokes the data transceiving operation close to the end, and generates a TCP packet, and then transmitted to the IP server entrusted
  • After the server returns the ACK number, the last ending

But in the end socket is not immediately deleted.

19. The package of basic knowledge

Composition packet: the packet header and the data is composed of two parts.

Head: the beginning of the packet control information comprising destination address, referred to as the head

Data: Packaging uploaded data, but also the contents of the package

20. The concept of nodes

Terminal nodes: the sender and the recipient referred to as terminal nodes

Forwarding node (intermediate node): forwarding device

21.IP module

IP module responsible for adding the two heads:. 1) MAC header: with an Ethernet header contains the MAC address

                                        2) IP header: IP with a head that contains an IP address

Whether to send and receive packet is a control packet or a data packet, IP packet send and receive various types of operation are the same.

Guess you like

Origin www.cnblogs.com/181118ljh123/p/12002300.html