Protocol protocol. Network protocol - what is it? Basic network protocols


Network protocol is a set of rules that allows connection and data exchange between two or more computers connected to the network. In fact, different protocols often describe only different sides one type of connection; taken together, they form the so-called protocol stack. Titles<протокол>And<стек протоколов>also point to software, which implements the protocol.

  • Application layer(Application layer). The upper (7th) level of the model ensures interaction between the network and the user. The layer allows user applications to access network services such as database query handler, file access, forwarding Email. It is also responsible for transmitting service information, providing applications with information about errors, and generating requests to the presentation layer. Example: HTTP, POP3, SMTP.
  • Presentation layer. Layer 6 is responsible for protocol conversion and data encoding/decoding. It converts application requests received from the application layer into a format for transmission over the network, and converts data received from the network into a format that applications can understand. The presentation layer can perform compression/decompression or encoding/decoding of data, as well as redirecting requests to another network resource, if they cannot be processed locally.
  • Session layer. Level 5 of the model is responsible for maintaining a communication session, which allows applications to interact with each other for a long time. The session layer manages session creation/termination, information exchange, task synchronization, determination of data transfer rights, and session maintenance during periods of application inactivity. Transmission synchronization is ensured by placing it in the data stream control points, starting from which the process is resumed if interaction is disrupted.
  • Transport layer. The 4th level of the model is designed to deliver data without errors, losses and duplication in the sequence in which they were transmitted. It does not matter what data is transmitted, from where and where, that is, it provides the transmission mechanism itself. It divides data blocks into fragments, the size of which depends on the protocol, combines short ones into one, and splits long ones. Protocols at this level are designed for point-to-point communication. Example: TCP, UDP
  • Network layer. Layer 3 of the OSI network model is designed to determine the data transmission path. Responsible for translating logical addresses and names into physical ones, determining the shortest routes, switching and routing, monitoring problems and congestion in the network. A network device such as a router operates at this level.
  • Data Link layer. This level is often called the channel level. This layer is designed to ensure the interaction of networks at the physical layer and control errors that may occur. Data received from physical level, it packs it into frames, checks for integrity, corrects errors if necessary, and sends it to the network layer. Data Link Layer can interact with one or more physical layers, monitoring and managing this interaction. The IEEE 802 specification divides this layer into 2 sublayers - MAC (Media Access Control) regulates access to the shared physical medium, LLC (Logical Link Control) provides network layer service. Switches and bridges operate at this level. In programming, this level represents the driver network card, V operating systems available software interface interaction between channel and network levels among themselves, this is not new level, but simply an implementation of the model for a specific OS. Examples of such interfaces: ODI, NDIS
  • Physical layer. The lowest level of the model is intended directly for transmitting the data stream. Transmits electrical or optical signals into a cable or radio broadcast and, accordingly, receives them and converts them into data bits in accordance with coding methods digital signals. In other words, it provides an interface between the network media and network device. At this level, signal concentrators (hubs), signal repeaters (repeaters) and media converters operate. Physical layer functions are implemented on all devices connected to the network. On the computer side, the physical layer functions are performed by the network adapter or serial port.

The main protocols used in the Internet:

  • TCP/IP
  • IMAP4
  • Gorpher

CLASSIFICATION OF COP BY SIZE. NAMES OF CS TYPES, THEIR APPROXIMATE LENGTH AND APPLICATION.

The local network

A local network is a short-range computer network: within a room, floor, building. Typically, such networks operate within one institution and have a short range: 1-10 km. The network is always departmental. Currently, there are no clear restrictions on the territorial dispersion of local area network subscribers. Typically, such a network is tied to a specific location. The class of local networks includes networks of individual enterprises, firms, banks, offices, etc. The local network provides high data transfer rates. And since in these networks the environment is usually controlled, the communication lines are short, the structural elements are homogeneous, the error rate in them is low and the exchange protocols are simplified. Local networks usually do not use communication means general purpose (telephone lines) to organize information exchange. Additional benefit Such a network consists of significant resource savings. So, instead of having a printer for each computer, you can only have one printer. Any computer on the network could send printing information to this printer

The main components of a local network: several PCs equipped with a network adapter, or network card; transmission medium connecting the necessary nodes; network software. To connect computers into a local network, you need to insert into each computer connected to the network network adapter(controller), which allows the computer to receive information from the local network and transmit data to the network, as well as connect computers with cables through which data is transferred between computers and other devices connected to the network (printers, scanners, etc.). In some types of networks, cables connect computers directly, in others, the cables are connected through special concentrator devices (or hubs), switches, etc. In small networks, computers are usually connected by cables to a hub, which transmits signals from one computer connected to it to another . Technical means determine only the potential capabilities of computer networks. Its true capabilities are determined by the software. What do local networks provide? saving space in memory, because many users use the same software products; good system protection when recording information; providing communication between individual users via computer mail.

Regional networks

Regional networks are networks that usually exist within a city, district, region, or country. They connect subscribers located at a considerable distance from each other. Typically, the distance between subscribers of a regional computer network is tens to hundreds of kilometers. They are a union of several local networks and part of a global one. They are not particularly specific in relation to the global one. Regional computer networks have much in common with local ones, but in many respects they are more complex. For example, in addition to data exchange and voice exchange, regional computer networks can transmit video and audio information. These networks are designed to support long distances than local area networks. They can be used to link multiple local computer networks into high-speed integrated network systems. Regional computer networks combine best characteristics local ( low level errors, high speed transmission) with a greater geographical extent. IN Lately they began to highlight the class corporate networks. They usually cover large corporations. Their scale and structure are determined by the needs of the enterprise owners.

Global networks

The global computer network unites subscribers located in different countries on different continents. Interaction between subscribers of such a network can be carried out on the basis of a telephone line, radio communication and systems satellite communications. Global computer networks solve the problem of unification information resources around the world and organizing access to these resources. To connect to remote computers And computer networks are used telephone networks. The process of data transmission over telephone lines must occur in the form of electrical oscillations - analogue sound signal, while in a computer information is stored in the form of codes. In order to transmit information from a computer over a telephone line, the codes must be converted into electrical vibrations. This process is called modulation. In order for the recipient to be able to read on his computer what is sent to him, electrical oscillations must be converted back into machine codes - demodulation. A device that converts data from digital form, in which it is stored in a computer, to analog (electrical vibrations), in which it can be transmitted over a telephone line, and vice versa, is called a modem (short for DEModulation Modulator). The computer, in this case, must have a special telecommunications program that controls the modem and also sends and receives signal sequences transmitted information. Global computer networks are created by combining local and regional computer networks. They are a conglomerate of different technologies. Compared to a local area network, most global networks have slower transfer speeds and a higher error rate. New technologies in the field of global computing networks are aimed at solving these problems. Global networks, in addition to covering very large territories, have a number of other features compared to local network. Global networks mainly use telephone lines as communication channels - these are slow channels with high level errors. However, high-speed fiber-optic and radio-satellite communication channels are now increasingly being introduced.

UDP (User Datagram Protocol) is designed for exchanging datagrams between processes of computers included in single network with packet switching. The UDP protocol uses IP as its lower layer protocol.

The UDP protocol provides application programs ability to send messages to other applications using minimal amount protocol parameters. This protocol does not provide packet delivery reliability, data duplication protection, or reliability against transmission failures. With the exception of application parameters—the sender and destination port numbers of the packet—UDP adds virtually nothing to the IP datagram.

UDP is much simpler than TCP and is useful in situations where strong reliability mechanisms TCP protocol are not required or will only be a hindrance for solving certain types of problems, for example, user authentication.

  • Source Port (16 bits) Sender port. This field may contain the port number from which the packet was sent when this is relevant (for example, the sender is waiting for a response). If this field is not used, it is filled with zeros.
  • Destination Port (16 bits) . The destination port is the computer port to which the packet will be delivered.
  • Length (16 bits) . Length field. The length, in bytes, of this datagram, including header and data. (The minimum value for this field is 8).
  • Checksum (16 bits) . Field checksum. The checksum of a UDP packet is the bits' complement of the 16-bit sum of 16-bit words (similar to TCP). The calculation includes: packet data, UDP packet header, pseudo-header (information from the IP protocol), 16-bit boundary alignment fields (zero).

Advantage UDP protocol is that it requires a minimum of settings and parameters to connect two processes with each other. This protocol is used when operating Domain Servers (Name Servers), when operating the TFTP protocol (Trivial File Transfer, Trivial Data Transfer Protocol), working with SNMP and building authentication systems. The UDP ID in the IP header is the number 17.

More detailed description The UDP protocol can be found in RFC-768.

Good bad

    The use of network firewalls and systems that effectively hide the organization of the internal network structure from external network, such as the Internet, everything becomes...

    Since the topic of security is important and cannot be covered at once, we have divided our series of articles into parts, and this time (in the second part) we are looking at setting up a firewall...

    The main task of the SMTP (Simple Mail Transfer Protocol) protocol is to ensure the transfer emails(mail). To work through SMTP protocol client…

Performs the functions of the transport layer of the OSI model.

When transferring from computer to computer over the Internet, TCP operates on upper level between two end systems, for example, a browser and a web server. TCP implements reliable transmission stream of bytes from one process to another. TCP implements flow control, congestion control, handshake, reliable transmission.

TCP Segment Header

Header structure
Bit 0 - 3 4 - 9 10 - 15 16 - 31
0 Source port Source Port Port of destination, Destination Port
32 Serial number, Sequence Number (SN)
64 Confirmation number
96 Header length Reserved Flags Window Size
128 Check sum Importance indicator
160 Options (optional, but almost always used)
160/192+ Data

Source Port, Destination Port

These 16-bit fields contain port numbers - numbers that are determined by a special list.

Source port identifies the client application from which the packets were sent. Response data is transmitted to the client based on this number.

Port of destination identifies the port to which the packet was sent.

Serial number

The sequence number serves two purposes:

  1. If the SYN flag is set, then this is the initial serial number- ISN (Initial Sequence Number), and the first byte of data that will be transmitted in the next packet will have a number equal to ISN + 1.
  2. Otherwise, if SYN is not set, the first byte of data transmitted in a given packet has this sequence number

Since a TCP stream can generally be longer than the number various conditions this field, then all operations with the serial number must be performed modulo 2 32 . This places a practical limitation on using TCP. If the transmission speed of the communication system is such that a sequence number overflow occurs during the MSL (maximum segment lifetime), then two segments with the same number may appear on the network, belonging to different parts of the stream, and the receiver will receive incorrect data.

Confirmation number

Acknowledgment Number (ACK SN)(32 bits) - if the ACK flag is set, then this field contains the sequence number of the octet that the sender of this segment wishes to receive. This means that all previous octets (with numbers from ISN+1 to ACK-1 inclusive) were successfully received.

Header length (data offset)

The header length (Data offset) occupies 4 bits and specifies the header length value, measured in 32-bit words. Minimum size is 20 bytes (five 32-bit words), and the maximum is 60 bytes (fifteen 32-bit words). The header length determines the offset of the payload relative to the start of the segment. For example, a Data offset of 1111 means that the header occupies fifteen 32-bit words (15 lines * 32 bits per line / 8 bits = 60 bytes).

Reserved

Reserved (6 bits) for future use and must be set to zero. Of these, two (5th and 6th) have already been defined:

  • C.W.R.(Congestion Window Reduced) - The Congestion Window Reduced field is set by the sender to indicate that a packet was received with the ECE flag set (RFC 3168)
  • ECE(ECN-Echo) - ECN Echo field - indicates that this node is capable of ECN (Explicit Congestion Notification) and to indicate to the sender about network congestion (RFC 3168)

Flags (control bits)

This field contains 6 bit flags:

  • URG- field "Importance Index" involved (English) Urgent pointer field is significant)
  • ACK- field "Confirmation number" involved (English) Acknowledgment field is significant)
  • P.S.H.- (English Push function) instructs the recipient to push the data accumulated in the receiving buffer into the user application
  • RST- disconnect connections, reset the buffer (buffer clearing) (eng. Reset the connection)
  • SYN- synchronization of sequence numbers (eng. Synchronize sequence numbers)
  • FIN(eng. final, bit) - the flag, when set, indicates the completion of the connection (eng. FIN bit used for connection termination).

Window size

Number of data bytes starting from last issue confirmations that the recipient of this packet can accept. In other words, the packet recipient has a buffer of “window size” bytes to receive data.

Check sum

The checksum field is the 16-bit complement of the sum of all 16-bit words of the header (including the pseudo-header) and data. If the segment from which the checksum is calculated has a length that is not a multiple of 16 bits, then the length of the segment is increased to a multiple of 16 by adding zero padding bits to it on the right. Padding bits (0) are not transmitted in the message and serve only to calculate the checksum. When calculating the checksum, the value of the checksum field itself is assumed to be 0.

Importance indicator

The 16-bit value of the positive offset from the sequence number in this segment. This field specifies the octet sequence number that ends the urgent data. The field is taken into account only for packets with the URG flag set. Used for out-of-band data.

Options

Can be used in some cases to expand the protocol. Sometimes used for testing. On this moment options almost always include 2 bytes NOP (in in this case 0x01) and 10 bytes specifying timestamps. You can calculate the length of the option field using the value of the offset field.

Video on the topic

Mechanism of the protocol

Unlike the traditional alternative, UDP, which can immediately begin transmitting packets, TCP establishes connections that must be created before transmitting data. A TCP connection can be divided into 3 stages:

  • Establishing a connection
  • Data transfer
  • Ending the connection

TCP session states

TCP session states
CLOSED The initial state of the node. Actually fictitious
LISTEN The server waits for connection requests from the client
SYN-SENT The client sent a request to the server to establish a connection and is waiting for a response
SYN-RECEIVED The server received a connection request, sent a response request and is waiting for confirmation
ESTABLISHED Connection established, data transfer in progress
FIN-WAIT-1 One of the parties (let's call it node-1) completes the connection by sending a segment with the FIN flag
CLOSE-WAIT The other side (node-2) enters this state by sending, in turn, an ACK segment and continues one-way transmission
FIN-WAIT-2 Node-1 receives ACK, continues reading and waits to receive a segment with the FIN flag
LAST-ACK Node-2 ends the transmission and sends the segment with the FIN flag
TIME-WAIT Node-1 received a segment with the FIN flag, sent a segment with the ACK flag and waits 2*MSL seconds before finally closing the connection
CLOSING Both sides initiated the connection closure at the same time: after sending a segment with the FIN flag, node-1 also receives a FIN segment, sends an ACK and waits for an ACK segment (acknowledgment of its disconnect request)

Establishing a connection

The process of starting a TCP session (also called a handshake) consists of three steps.

1. A client that intends to establish a connection sends a segment with a sequence number and a SYN flag to the server.

  • The server receives the segment, remembers the sequence number, and attempts to create a socket (buffers and control memory structures) to serve the new client.
    • If successful, the server sends the client a segment with a sequence number and the SYN and ACK flags, and enters the SYN-RECEIVED state.
    • In case of failure, the server sends the client a segment with the RST flag.

2. If the client receives a segment with the SYN flag, then it remembers the sequence number and sends the segment with the ACK flag.

  • If the client also receives the ACK flag at the same time (which usually happens), then it enters the ESTABLISHED state.
  • If the client receives a segment with the RST flag, it stops trying to connect.
  • If the client does not receive a response within 10 seconds, it repeats the connection process again.

3. If the server in the SYN-RECEIVED state receives a segment with the ACK flag, then it transitions to the ESTABLISHED state.

  • Otherwise, after a timeout, it closes the socket and enters the CLOSED state.

The process is called “three-way handshake”, because although it is possible to establish a connection using four segments (SYN to the server, ACK to the client, SYN to the client, ACK to the server), in practice, three segments are used to save time.

Example of a basic 3-step approval:

TCP A TCP B 1. CLOSED LISTEN 2. SYN-SENT --> --> SYN-RECEIVED 3. ESTABLISHED<-- <-- SYN-RECEIVED 4. ESTABLISHED --> --> ESTABLISHED 5. ESTABLISHED<-- <-- ESTABLISHED

On line 2, TCP A begins sending a SYN segment indicating the use of sequence numbers, starting with 100. On line 3, TCP B sends a SYN and an acknowledgment for the received SYN to TCP A. It should be noted that the acknowledgment field indicates that TCP B is waiting for the sequence number to be received 101, confirming SYN number 100.

On line 4, TCP A responds with an empty segment with an ACK for the SYN segment from TCP B; on line 5 TCP B sends some data. Note that the segment acknowledgment number in line 5 (ACK=101) is the same as the sequence number in line 4 (SEQ=101), since ACK does not occupy sequence number space (if this is done, you will have to acknowledge acknowledgments - ACK for ACK).

Data transfer

When exchanging data, the receiver uses the sequence number contained in the received segments to restore their original order. The receiver notifies the sending side of the sequence number up to which it successfully received data, including it in the “acknowledgment number” field. All received data related to the interval of confirmed sequences is ignored. If the received segment contains a sequence number greater than expected, then the data from the segment is buffered, but the confirmed sequence number is not changed. If a segment corresponding to the expected sequence number is subsequently received, the order of the data will be automatically restored based on the sequence numbers in the segments.

To ensure that the sending side does not send more data than the receiver can process, TCP contains flow controls. To do this, use the “window” field. In segments sent from the receiver to the transmitting side, the current size of the receiving buffer is indicated in the “window” field. The sending side maintains the window size and sends no more data than indicated by the receiver. If the receiver has specified a window size of zero, then no data is transmitted in the direction of this node until the receiver reports a larger window size.

In some cases, the sending application may explicitly request that data be pushed in sequence to the receiving application without buffering it. The PSH flag is used for this. If the PSH flag is detected in the received segment, the TCP implementation returns all currently buffered data to the receiving application. Push is used, for example, in interactive applications. In network terminals there is no point in waiting for user input after he has finished typing a command. Therefore, the last segment containing the command must contain the PSH flag so that the application on the receiving side can begin executing it.

Ending the connection

Terminating a connection can be considered in three steps:

  1. Sending the FIN flag to the server from the client to terminate the connection.
  2. The server sends the client response flags ACK, FIN, indicating that the connection is closed.
  3. After receiving these flags, the client closes the connection and sends an ACK to the server to confirm that the connection is closed.

Known Issues

Maximum segment size

TCP requires an explicit maximum segment size (MSS) if a virtual connection is made over a network segment where the maximum unit size (MTU) is less than the standard Ethernet MTU (1500 bytes).

In tunneling protocols such as GRE, IPIP, and also PPPoE, the tunnel MTU is smaller than the standard one, so the maximum TCP segment size has a packet length greater than the MTU. This leads to fragmentation and reduced transmission speed of useful data. If fragmentation is prohibited on any node, then from the user’s side this looks like a “stuck” connection. In this case, “freezing” can occur at arbitrary times, namely when the sender used segments longer than the permissible size. To solve this problem, routers use Firewall rules that add an MSS parameter to all packets that initiate connections so that the sender uses segments of a valid size.

MSS can also be controlled by operating system settings.

Detection of errors during data transmission

Although the protocol verifies the checksum on each segment, the algorithm used is considered weak. So, in 2008, an error in the transmission of one bit, which was not detected by network tools, led to the shutdown of Amazon Web Services system servers.

In general, distributed network applications are encouraged to use additional software to ensure the integrity of transmitted information.

Protocol attacks

The protocol's shortcomings manifest themselves in successful theoretical and practical attacks, in which an attacker can gain access to transmitted data, impersonate the other party, or render the system inoperable.

Implementation

Pseudo-title

The TCP header does not contain information about the sender and recipient addresses, so even if the recipient port matches, it is impossible to say with certainty that the message arrived in the right place. Since the purpose of the TCP protocol is the reliable delivery of messages, this point is of fundamental importance. This problem could be solved in different ways. The most obvious is to add information about the destination address to the TCP header, but this, firstly, leads to duplication of information, which reduces the share of useful information carried by the TCP segment, and secondly, it violates the principle of encapsulation of the OSI model. Therefore, the protocol developers took a different route and used an additional pseudo-header.

HTTP is a protocol for transferring hypertext between distributed systems. In fact, http is a fundamental element of the modern Web. As self-respecting web developers, we should know as much as possible about it.

Let's look at this protocol through the lens of our profession. In the first part, we'll go over the basics and look at requests/responses. In the next article we will look at more detailed features, such as caching, connection processing and authentication.

Also in this article I will mainly refer to the RFC 2616 standard: Hypertext Transfer Protocol -- HTTP/1.1.

HTTP Basics

HTTP enables communication between multiple hosts and clients, and supports a range of network settings.

Basically, TCP/IP is used for communication, but this is not the only possible option. By default, TCP/IP uses port 80, but others can be used.

Communication between the host and the client occurs in two stages: request and response. The client generates an HTTP request, in response to which the server provides a response (message). A little later, we will look at this scheme of work in more detail.

The current version of the HTTP protocol is 1.1, in which some new features have been introduced. In my opinion, the most important of them are: support for a constantly open connection, a new data transfer mechanism chunked transfer encoding, new headers for caching. We will look at some of this in the second part of this article.

URL

The core of web communication is the request, which is sent through the Uniform Resource Locator (URL). I'm sure you already know what a URL is, but for the sake of completeness, I decided to say a few words. The URL structure is very simple and consists of the following components:

The protocol can be either http for regular connections or https for more secure data exchange. The default port is 80. This is followed by the path to the resource on the server and a chain of parameters.

Methods

Using a URL, we define the exact name of the host we want to communicate with, but what action we need to perform can only be communicated using the HTTP method. Of course, there are several types of actions that we can take. HTTP implements the most necessary ones, suitable for the needs of most applications.

Existing methods:

GET: Access an existing resource. The URL lists all the necessary information so that the server can find and return the requested resource as a response.

POST: Used to create a new resource. A POST request usually contains all the necessary information to create a new resource.

PUT: Update the current resource. The PUT request contains the data to be updated.

DELETE: Used to delete an existing resource.

These methods are the most popular and are most often used by various tools and frameworks. In some cases, PUT and DELETE requests are sent by sending a POST, the content of which indicates the action that needs to be performed on the resource: create, update or delete.

HTTP also supports other methods:

HEAD: Similar to GET. The difference is that with this type of request no message is transmitted. The server only receives the headers. Used, for example, to determine whether a resource has been modified.

TRACE: during transmission, the request passes through many access points and proxy servers, each of which enters its own information: IP, DNS. Using this method, you can see all the intermediate information.

OPTIONS: Used to define server capabilities, settings, and configuration for a specific resource.

Status codes

In response to a request from the client, the server sends a response, which also contains a status code. This code has a special meaning so that the client can more clearly understand how to interpret the response:

1xx: Information messages

A set of these codes was introduced in HTTP/1.1. The server can send a request of the form: Expect: 100-continue, which means that the client is still sending the rest of the request. Clients running HTTP/1.0 ignore these headers.

2xx: Success messages

If the client received a code from the 2xx series, then the request was sent successfully. The most common option is 200 OK. With a GET request, the server sends a response in the body of the message. There are also other possible answers:

  • 202 Accepted: The request is accepted, but may not contain the resource in the response. This is useful for asynchronous requests on the server side. The server determines whether to send the resource or not.
  • 204 No Content: There is no message in the response body.
  • 205 Reset Content: Instructs the server to reset the presentation of the document.
  • 206 Partial Content: The response contains only part of the content. Additional headers determine the total length of the content and other information.

3xx: Redirect

A kind of message to the client about the need to take one more action. The most common use case is to redirect the client to another address.

  • 301 Moved Permanently: The resource can now be found at a different URL.
  • 303 See Other: The resource can temporarily be found at a different URL. The Location header contains a temporary URL.
  • 304 Not Modified: The server determines that the resource has not been modified and the client needs to use the cached version of the response. To check the identity of information, ETag (Entity Tag hash) is used;

4xx: Client errors

This message class is used by the server if it decides that the request was sent in error. The most common code is 404 Not Found. This means that the resource was not found on the server. Other possible codes:

  • 400 Bad Request: The question was formed incorrectly.
  • 401 Unauthorized: Authentication is required to make a request. The information is transmitted through the Authorization header.
  • 403 Forbidden: The server did not allow access to the resource.
  • 405 Method Not Allowed: An invalid HTTP method was used to access the resource.
  • 409 Conflict: the server cannot fully process the request because tries to change a newer version of a resource. This often happens with PUT requests.

5xx: Server errors

A series of codes that are used to detect a server error when processing a request. The most common: 500 Internal Server Error. Other options:

  • 501 Not Implemented: The server does not support the requested functionality.
  • 503 Service Unavailable: This can happen if the server has an error or is overloaded. Usually in this case, the server does not respond, and the time given for the response expires.

Request/Response Message Formats

In the following image you can see a schematic process of sending a request by the client, processing and sending a response by the server.

Let's look at the structure of a message transmitted via HTTP:

Message = *() CRLF [ ] = Request-Line | Status-Line = Field-Name ":" Field-Value

There must be a blank line between the header and body of the message. There can be several headings:

The response body can contain all or part of the information if the corresponding feature is enabled (Transfer-Encoding: chunked). HTTP/1.1 also supports the Transfer-Encoding header.

General Headings

Here are several types of headers that are used in both requests and responses:

General-header = Cache-Control | Connection | Date | Pragma | Trailer | Transfer-Encoding | Upgrade | Via | Warning

We have already covered some things in this article, some we will discuss in more detail in the second part.

The via header is used in a TRACE request, and is updated by all proxy servers.

The Pragma header is used to list custom headers. For example, Pragma: no-cache is the same as Cache-Control: no-cache. We'll talk more about this in part two.

The Date header is used to store the date and time of the request/response.

The Upgrade header is used to change the protocol.

Transfer-Encoding is intended to split the response into multiple chunks using Transfer-Encoding: chunked. This is a new feature in HTTP/1.1.

Entity Headers

Entity headers convey meta information about the content:

Entity-header = Allow | Content-Encoding | Content-Language | Content-Length | Content-Location | Content-MD5 | Content-Range | Content-Type | Expires | Last-Modified

All headers prefixed with Content- provide information about the structure, encoding, and size of the message body.

The Expires header contains the expiration time and date of the entity. The value “never expires” means time + 1 code from the current moment. Last-Modified contains the time and date the entity was last modified.

Using these headers, you can specify the information necessary for your tasks.

Request Format

The request looks something like this:

Request-Line = Method SP URI SP HTTP-Version CRLF Method = "OPTIONS" | "HEAD" | "GET" | "POST" | "PUT" | "DELETE" | "TRACE"

SP is the separator between tokens. The HTTP version is specified in HTTP-Version. The actual request looks like this:

GET /articles/http-basics HTTP/1.1 Host: www.articles.com Connection: keep-alive Cache-Control: no-cache Pragma: no-cache Accept: text/html,application/xhtml+xml,application/xml; q=0.9,*/*;q=0.8

List of possible request headers:

Request-header = Accept | Accept-Charset | Accept-Encoding | Accept-Language | Authorization | Expect | From | Host | If-Match | If-Modified-Since | If-None-Match | If-Range | If-Unmodified-Since | Max-Forwards | Proxy-Authorization | Range | Referrer | TE | User-Agent

The Accept header specifies the supported mime types, language, and character encoding. The From, Host, Referer, and User-Agent headers contain information about the client. If- prefixes are intended to create conditions. If the condition does not pass, a 304 Not Modified error will occur.

Response Format

The response format differs only in the status and a number of headers. The status looks like this:

Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

  • HTTP version
  • Status code
  • Human-readable status message

The normal status looks something like this:

HTTP/1.1 200 OK

The response headers can be as follows:

Response-header = Accept-Ranges | Age | ETag | Location | Proxy-Authenticate | Retry-After | Server | Vary | WWW-Authenticate

  • Age is the time in seconds when the message was created on the server.
  • ETag MD5 entities to check for changes and modifications to the response.
  • Location is used for redirection and contains the new URL.
  • Server specifies the server where the response was generated.

I think that's enough theory for today. Now let's take a look at the tools we can use to monitor HTTP messages.

Tools for detecting HTTP traffic

There are many tools for monitoring HTTP traffic. Here are a few of them:

The most commonly used is Chrome Developers Tools:

If we talk about a debugger, you can use Fiddler:

To monitor HTTP traffic you will need curl, tcpdump and tshark.

Libraries for working with HTTP - jQuery AJAX

Since jQuery is so popular, it also has tools for handling HTTP responses for AJAX requests. Information about jQuery.ajax(settings) can be found on the official website.

By passing a settings object and using the beforeSend callback function, we can set the request headers using the setRequestHeader() method.

$.ajax(( url: "http://www.articles.com/latest", type: "GET", beforeSend: function (jqXHR) ( jqXHR.setRequestHeader("Accepts-Language", "en-US,en "); ) ));

If you want to process the request status, you can do it like this:

$.ajax(( statusCode: ( 404: function() ( alert("page not found"); ) ) ));

Bottom line

Here it is, a tour of the basics of the HTTP protocol. The second part will contain even more interesting facts and examples.

Not so long ago, the organization of local networks required the mandatory use of the correct protocol. This choice influenced what types of computers could be connected to it. Today this problem has practically disappeared. Modern networks have replaced everything that existed before. This is a universal solution that can be used on any operating system.

Terminology

A network protocol is an established language in which programs communicate. Data forwarding is the movement of some stream of bits along a cable. In order for it to reach the target computer and be represented there as data, a certain set of rules is required. They are the ones that are spelled out in the standard protocols. They are usually said to have a nesting level. What does it mean? There is a physical layer, which is a list of definitions, for example, what a network cable can be, the thickness of its cores and other parameters. Let's say we are talking about a working cable. Then data packets will be sent over it. But which computer will accept them? Here the link layer comes into play, and the packet header indicates the physical address of each machine - a certain number embedded in it is called the MAC address.

Network hierarchy

The data link layer is the same as Ethernet. A package contains a set of specific parameters that define its type. The data is directly dependent on this type, and its content belongs to the network layer. There are two most common protocols: ARP, which is responsible for resolving IP addresses to MAC, and the IP protocol itself. You can give the structure of an IP packet. All data that is transferred with its help is already sent to a specific network address. The packet contains a number in a specified format indicating the protocol type.

The two most common types are TCP and UDP. There is a certain difference between them, namely that the first is characterized by the maximum degree of reliability, because when sending a package, it constantly sends a request to receive it. The second network protocol is a convenient tool, for example, when listening to Internet radio. This involves sending packets without any verification that they were received. If it has arrived, then you will be able to listen to the radio, but if not, then there is no point in checking and monitoring.

Features of package delivery

The package must indicate the port number where the shipment is being made. Typically this parameter is determined by the protocol type at the application level - depending on the application to which the information is sent. You can also use non-standard service ports; no one prohibits this. The most well-known network protocols in this case are HTTP and POP3. Retrieves a specific package nesting hierarchy. An Ethernet packet contains IP, then TCP or UDP, and then application-specific data.

Distinctive characteristics

The network protocol, unlike protocols, is not tied to specific equipment. Their implementation occurs at the software level, so they can be installed and removed at any time.

IP and TCP/IP

This network protocol is used not only on the Internet, but also within it. It represents the transport and network layer, due to which data is transferred in blocks. For many years it was used only in UNIX networks, and now, when the Internet has grown quite rapidly, the IP network protocol has begun to be used in almost every type of local computer network. It currently serves as the primary protocol for most services running on operating systems.

Local and switched networks

Old network protocols required some specific knowledge, and TCP/IP is used by users who have never even seen network cards. Access to the Internet using a modem or local network is provided provided that the same protocol is used. And the process of setting it up completely depends on the type of connection used. It is worth noting that network layer protocols are different from all others, and the parameters for accessing a local network or using a modem also have certain nuances. It is better to establish a dial-up connection using an automatic configuration program that is supplied by the provider itself. Otherwise, you need to manually enter all the necessary parameters. You can consider the main network protocols.

IPX protocol

This kit was developed by Novell for use with its own NetWare OS. IPX is partially similar to TCP/IP, that is, it includes some protocols from this package, but the company has copyrighted it. However, Microsoft has created its own protocol compatible with this, designed for operating systems from the Windows family. IPX is a network protocol that is functionally similar to IP. SPX is a transport layer tool that is designed to facilitate the exchange of packet data between separate machines.

At the moment, this protocol is used only in networks with servers where older versions of the NetWare operating system are installed. It is often used in conjunction with some other set of network protocols. Now Nowell has completely switched to the new universal TCP/IP protocol.

NetBEUI

This network protocol is used in small networks. It was first introduced in Windows NT 3.1, and in several subsequent versions of the system, where it was used by default. In the latest versions of systems, its place was taken by the already familiar TCP/IP. This protocol is quite simple and lacks many of the features found in more advanced variants. It is not suitable for internetworking. It can be useful for simple things, but now it is not even presented as a standard OS component; it must be installed independently from disk.

NetBEUI is a convenient tool for creating a direct cable connection, and in this sense it is the minimum protocol that is required to form a peer-to-peer network in versions of Windows 9x.

conclusions

It is important to remember certain points. At the moment, there is more than one network protocol. All of them are designed for communication, but each of them has completely different tasks, and has advantages and disadvantages compared to the others. The use of each of them presupposes the presence of certain operating conditions, which are usually prescribed by the protocol itself. When choosing a particular solution, you should rely on this parameter.







2024 gtavrl.ru.