Transport protocols - UDP. Difference between TCP and UDP

At the data link and network protocol levels TCP/IP packet, which concern the basic mechanism for transferring blocks of data between countries and between networks, are the basics TCP/IP. They use the protocol stack, but they are not used directly in applications that run on the protocol TCP/IP. In this article, we'll look at two protocols that are used by applications: User Datagram Protocol (UDP) and Transmission Control Protocol (TCP).

User Datagram Protocol
User Datagram Protocol is a very simple protocol. Like IP, it is a reliable connectionless protocol. You don't need to establish a connection to the host to exchange data with it using UDP, and there is no mechanism to ensure the transmitted data.
Block of data transmitted using UDP called a datagram. UDP adds four 16-bit header fields (8 bytes) to the transmitted data. These fields are: length field, checksum field, and source and destination port number. "Port", in this context, represents the software of the port, not the hardware port.
The port number concept is common to both UDP and TCP. Port numbers determine which protocol module forwards (or receives) data. Most protocols have standard ports that are commonly used for this. For example, the Telnet protocol typically uses port 23. Simple Mail Transfer Protocol (SMTP), uses port 25. Using standard port numbers allows clients to communicate with the server without first deciding which port to use.
Port and protocol number in the header field IP duplicate each other to some extent, although the protocol fields are not available to higher-level protocols. IP uses the protocol field to determine where data should be sent to UDP or TCP modules. UDP or TCP use the port number to determine which application layer protocol should receive data.
Despite, UDP is not foolproof, it is still a suitable choice for many applications. It is used by real-time applications such as streaming audio and video, where if data is lost, it is better to do without it than to send it again in order. It is also used by protocols such as Simple Network Management Protocol (SNMP).
Broadcast
UDP suitable for information broadcasting because it does not require an open connection connection. The targets of a broadcast message are determined by the sender, to the specified destination IP address. UDP datagrams with destination IP address are all binary 255.255.255.255) and will be received by every host on the local network. Pay attention to the word local: datagrams with such an address will not be accepted by the router to the Internet.
Transmissions can be directed to specific networks. UDP datagrams from the host and subnet parts of the IP address set as binary are broadcast to all hosts on all subnets of the network that corresponds to the pure part of the IP address. If only the receiving end (in other words, all the bits that are zero in the subnet mask) is set to binary, then broadcasting is restricted to all hosts in the subnet that matches the rest of the address.
Multicast is used to transmit data among a group of hosts that have expressed a desire to receive it. Multicast UDP the datagram has a destination address in which the first four bits are 1110, providing addresses in the range 224.xxx to 239.xxx The remaining bits of the address are used to designate the multicast group. It's more like a radio or TV channel. So, for example, 224.0.1.1 is used for the NTP protocol. If TCP/IP applications want to receive a multicast message, they must join the appropriate multicast group, which it does by passing the group's address into the protocol stack.
Broadcasters essentially filter the transmission. Multicaster does not consider individual messages for each host that joins the group. Instead, messages are broadcast, and drivers on each host decide whether to ignore them or pass the contents on to the protocol stack.
This means that multicast messages must be broadcast across the entire Internet, since the multicaster does not know which hosts want to receive the messages. Fortunately, this is not necessary. IP uses a protocol called Internet Group Management Protocol (IGMP) to tell routers which hosts want to receive multicast group messages so that messages are sent only where they are needed.
Transmission Control Protocol
Transmission Control Protocol is a transport layer protocol and is used by most Internet applications such as Telnet, FTP and HTTP. This is a connection-oriented protocol. This means that two computers - one a client, the other a server - need to establish a connection between them before data can be transferred between them.
TCP provides reliability. Application that uses TCP knows that it is sending data received at the other end, and that it received it correctly. TCP uses checksums on both headers and data. When receiving data, TCP sends confirmation back to the sender. If the sender does not receive confirmation within a certain period of time, the data is resent.
TCP includes mechanisms to ensure data arrives in reverse order in the order it was sent. It also implements flow control so that the sender cannot overwhelm the receiver of the data.
TCP transmits data using IP in blocks called segments. The length of the segment is determined by the protocol. In addition to the IP header, each segment consists of 20 bytes of header. Heading TCP begins with a 16-bit source and destination port number field. Like UDP, these fields define the application level that is aimed at receiving data. The IP address and port number together uniquely identify the services running for the host and the pair known as the socket.
Next in the header is a 32-bit sequence number. This number specifies the position in the data stream that the first byte of data in the segment should occupy. Serial number TCP allows the data stream to be kept in the correct order, although segments may be derived from a sequence.
The next field is a 32-bit field that is used to convey back to the sender that the data was received correctly. If ACK is a flag, which it usually is, then this field contains the position of the next byte of data that the sender of the segment expects to receive.
IN TCP there is no need for every segment of data to be recognized. The value in the confirmation field is interpreted as “all data received OK so far.” This saves bandwidth when all data is routed in one direction, reducing the need for segment recognition. If data is sent simultaneously in both directions, as in full duplex communication, then stamps are not associated with costs, since a data segment one way can contain an acknowledgment for data sent the other way.
Next in the header is a 16-bit field containing the header length and flags. TCP headers may contain additional fields, so the length can vary from 20 to 60 bytes. Flags: URG, ACK (which we already mentioned), PSH, RST, SYN and FIN. Later, we'll look at some other flags.
The header contains a field called window size, which gives the number of bytes the receiver can receive. There is also a 16-bit checksum covering both the header and data. Finally (before additional data) there is a field called the “urgency indicator”. When the URG flag is set, this value is interpreted as a sequence number offset. It identifies the start of data in a stream that needs to be processed urgently. This data is often referred to as "out-of-group" data. An example of its use is when the user presses the break key to interrupt exiting the program during a Telnet session.

When we talk about information security, we mean the confidentiality, integrity and availability of information at any given time. And if everything is clear with confidentiality and availability, then how to ensure the integrity of information when transmitted over the network? To solve this problem, we will need knowledge of network protocols. In this article we will look at the TCP and UDP protocols. They are part of the TCP/IP protocol stack, belong to the transport layer of the OSI model and are used to transfer information from node to node.

What is each of these protocols, what is their difference and when is it more advisable to use a UDP connection and when is TCP.

UDP

UDP protocol is a protocol that provides data transmission (datagrams) without first creating a connection between hosts. When sending datagrams, there is no certainty about the existence of the recipient and his readiness for exchange. The UDP network protocol also does not provide ordering of datagrams upon receipt. It is used by applications for which delivery time is essential, when there is no way to wait for delayed or request lost packets, for example, in real-time systems. Datagrams may be delivered out of order, duplicated, or not delivered at all. This is why UDP is called the “Unreliable Datagram Protocol”.

Applications using the UDP protocol are not sensitive to data loss, datagram out-of-order, and duplication. At the same time, they can use reliability mechanisms at the application level.

TCP

The TCP data transfer protocol is a protocol that ensures reliable delivery of data packets; it ensures the establishment of a connection between two hosts using the “handshake” method, after which data can be exchanged.

Before packets are transmitted via a TCP connection, a session is established with the recipient, within which data is then transferred. This ensures that the recipient exists and is ready to receive data. Once the transfer is complete, the session is closed, the recipient is notified that there will be no more data, and the sender is notified that the recipient has been notified.

Each packet during exchange has its own serial number. TCP automatically orders packets using a sequence number and passes them to the application layer after concatenation. After sending several packets, confirmation and the sequence number of the next packet are expected. If confirmation is not received, the sending is repeated; if attempts are unsuccessful, the session is terminated. The number of data packets for which confirmation will be requested depends on the reliability of the network. If data is lost, confirmation is automatically requested more frequently. This is called the sliding window mechanism, which allows TCP to operate on networks regardless of their reliability level.

The use of TCP is advisable where data loss is unacceptable, for example, during authorization, as well as when transmitting encrypted information.

TCP and UDP differences

Does this mean that UDP should not be used? Not at all. Due to the lack of a “delivery guarantee,” UDP provides higher data transfer rates than TCP. For this reason, UDP is optimal for network and online games, watching streaming video, organizing video communications and IP telephony.

Share useful information with your loved ones.

UDP protocol

User Datagram Protocol (UDP) is a simple, connectionless, datagram-oriented protocol that provides fast, but not necessarily reliable, transport service. It supports one-to-many interactions and is therefore often used for broadcast and multicast datagram transmission.

Internet Protocol (IP) is the main protocol of the Internet. Transmission Control Protocol (TCP) and UDP are transport layer protocols built on top of an underlying protocol.

TCP/IP is a set of protocols, also called the Internet Protocol Suite, consisting of four layers. Remember that TCP/IP is not just one protocol, but a family or set of protocols that consists of other lower-level protocols such as IP, TCP, and UDP. UDP sits at the transport layer on top of IP (network layer protocol). The transport layer provides communication between networks through gateways. It uses IP addresses to send data packets over the Internet or another network using a variety of device drivers.

Before we start learning how UDP works, let's look at some basic terminology that you need to know well. Below we will briefly define the main terms associated with UDP:

Packages

In data communications, a packet is a sequence of binary digits representing data and control signals that are transmitted and switched through the host. Inside the package, this information is located in accordance with a special format.

Datagrams

A datagram is a single, independent packet of data that carries enough information to travel from source to destination, so no additional traffic is required between the source, destination, and transport network.

MTU (Maximum Transmission Unit)

MTU characterizes the link layer and corresponds to the maximum number of bytes that can be transmitted in one packet. In other words, the MTU is the largest packet that a given network environment can carry. For example, Ethernet has a fixed MTU of 1500 bytes. In UDP, if the datagram size is greater than the MTU, the IP protocol performs fragmentation by breaking the datagram into smaller pieces (fragments) so that each fragment is less than the MTU.

Ports

To match incoming data to a specific process running on a computer, UDP uses ports. UDP forwards the packet to the appropriate location using the port number specified in the UDP header of the datagram. Ports are represented by 16-bit numbers and therefore take on values ​​ranging from 0 to 65,535. Ports, which are also called logical connection endpoints, are divided into three categories:

    Well known ports - from 0 to 1023

    Registered ports - from 1024 to 49151

    Dynamic/private ports - 49152 to 65535

Note that UDP ports can receive more than one message at any given time. In some cases, TCP and UDP services may use the same port numbers, such as 7 (Echo) or 23 (Telnet).

UDP uses the following known ports:

The list of UDP and TCP ports is maintained by the IANA (Internet Assigned Numbers Authority).

IP addresses

An IP datagram consists of 32-bit source and destination IP addresses. The destination IP address specifies the endpoint for the UDP datagram, and the source IP address is used to obtain information about who sent the message. At the destination, packets are filtered and those whose source addresses are not included in the valid set of addresses are discarded without notification to the sender.

A unicast IP address uniquely identifies a host on a network, whereas a multicast IP address identifies a specific group of addresses on a network. Broadcast IP addresses are received and processed by all hosts on a local network or a specific subnet.

TTL

The time-to-live, or TTL (time-to-live) value allows you to set an upper limit on the number of routers through which a datagram can pass. The TTL value prevents packets from getting caught in endless loops. It is initialized by the sender and decremented by one by each router that processes the datagram. When the TTL value becomes zero, the datagram is discarded.

Group mailing

Multicast is an open, standards-based method for distributing identical information to multiple users simultaneously. Multicast is the main feature of the UDP protocol; it is not possible with the TCP protocol. Multicast allows one-to-many interaction, for example making possible uses such as sending news and mail to multiple recipients, Internet radio, or real-time demo programs. Multicast does not load the network as much as broadcast transmission, since the data is sent to several users at once:

How UDP works

When a UDP-based application sends data to another host on the network, UDP appends it with an eight-bit header containing the destination and source port numbers, the total length of the data, and a checksum. IP adds its header on top of the UDP datagram, forming an IP datagram:

The previous figure indicates that the total length of the UDP header is eight bytes. The theoretical maximum size of an IP datagram is 65,535 bytes. With 20 bytes of IP header and 8 bytes of UDP header, the user data length can be up to 65,507 bytes. However, most programs work with smaller data sizes. Thus, for most applications, the default length is approximately 8192 bytes, because this is the amount of data read and written by the Network File System (NFS). You can set the sizes of the input and output buffers.

The checksum is needed to check whether the data was delivered to its destination correctly or was corrupted. It covers both the UDP header and the data. A filler byte is used if the total number of octets in the datagram is odd. If the received checksum is zero, the recipient records a checksum error and discards the datagram. Although a checksum is an optional feature, it is always recommended to include it.

In the next step, the IP layer adds 20 bytes of header that includes the TTL, source and destination IP addresses, and other information. This action is called IP encapsulation.

As mentioned earlier, the maximum packet size is 65,507 bytes. If a packet exceeds the default MTU size, the IP layer splits the packet into segments. These segments are called fragments, and the process of breaking data into segments is fragmentation. The IP header contains all the fragment information.

When the sending application "throws" a datagram onto the network, it is routed to the destination IP address specified in the IP header. When passing through a router, the time to live (TTL) value in the IP header is reduced by one.

When a datagram arrives at a given destination and port, the IP layer checks its header to see if the datagram is fragmented. If so, the datagram is assembled according to the information in the header. Finally, the application layer retrieves the filtered data by removing the header.

Disadvantages of UDP

Compared to TCP, UDP has the following disadvantages:

    No acknowledgment signals. Before sending a UDP packet, the sending side does not exchange handshake signals with the receiving side. Therefore, the sender has no way of knowing whether the datagram has reached the destination system. As a result, UDP cannot guarantee that the data will actually be delivered to the destination (for example, if the end system or network is down).

    In contrast, TCP is connection-oriented and enables communication between network-connected hosts using packets. TCP uses handshaking signals to verify that data has been transported successfully.

    Using sessions. TCP's connection-oriented nature is supported by sessions between hosts. TCP uses a session identifier to keep track of connections between two hosts. UDP does not have session support due to its connectionless nature.

    Reliability. UDP does not guarantee that only one copy of the data will be delivered to the recipient. To send a large amount of data to the end system, UDP breaks it up into small pieces. UDP does not guarantee that these parts will be delivered to their destination in the same order in which they were created at the source. In contrast, TCP uses sequence numbers along with port numbers and regularly sent acknowledgments to ensure orderly delivery of data.

    Safety. TCP is more secure than UDP. In many organizations, firewalls and routers do not allow UDP packets through. This is because hackers can take advantage of UDP ports without making explicit connections.

    Flow control. UDP has no flow control, and as a result, a poorly designed UDP application can consume a significant portion of network bandwidth.

Benefits of UDP

Compared to TCP, UDP has the following advantages:

    No connection established. UDP is a connectionless protocol, so it eliminates the overhead associated with establishing connections. Since UDP does not use handshakes, connection delays are also avoided. This is why DNS favors UDP over TCP - DNS would be much slower if it ran over TCP.

    Speed. UDP is faster than TCP. For this reason, many applications prefer UDP over TCP. The same things that make TCP more robust (such as handshake signals) also slow it down.

    Topological diversity. UDP supports one-to-one and one-to-many communications, while TCP only supports one-to-one communications.

    Overheads. Working with TCP means increased overhead, the overhead imposed by UDP is significantly lower. TCP uses significantly more operating system resources than UDP, and as a result, UDP is widely used in environments where servers serve many clients simultaneously.

    Header size. For each packet, the UDP header is only eight bytes long, while TCP has 20-byte headers, and therefore UDP consumes less network bandwidth.

I really like the whole series of articles, plus I always wanted to try myself as a translator. Perhaps the article will seem too obvious to experienced developers, but it seems to me that it will be useful in any case.

Hello, my name is Glenn Fiedler and I welcome you to the first article in my online book, Network Programming for Game Developers.

In this article, we will start with the most basic aspects of network programming - receiving and transmitting data over the network. Receiving and transmitting data is the most basic and simplest part of the entire range of tasks that network programmers do, but it is often difficult to determine which way is best to proceed. Pay enough attention to this part - if you are left with a misunderstanding, it can lead to dire consequences for your multiplayer game later!

You've most likely already heard something about sockets, and you may know that they come in two main types - TCP and UDP. The first thing you need to decide when developing a multiplayer game is what type of sockets to use - TCP, UDP, or both?

The choice of socket type depends entirely on the genre of the game you are developing. In this series of articles, I will assume that you are writing an action game - like Halo, Battlefield 1942, Quake, Unreal, CounterStrike, Team Fortress, etc.

Now we will take a closer look at the properties of each type of socket (taking into account the fact that we are developing an action-style game), and go a little deeper into the details of how the Internet works. After a detailed review, the right option will become obvious!

TCP stands for “transmission control protocol” and IP stands for “internet protocol”. Together they underpin almost everything you do online, from web browsing to IRC and email communications - all running on TCP/IP.

If you have ever used TCP sockets, then you should know that TCP is a protocol that uses the principle of a reliable connection. This means that you establish a connection between two computers, and then send data between them, just as if you were writing information to a file on one computer and reading it from the same file on another.

In this case, the connection is considered reliable and consistent - that is, all the information you send is guaranteed to reach the recipient in the same order in which it was sent. Also, a TCP connection can be considered a continuous stream of data - the protocol itself takes care of breaking the data into packets and sending them over the network.

One more time - everything is as simple as normal writing or reading from a file. Elementary Watson!

But this ease of use is completely different from what actually happens "under the hood", at a lower level - the IP protocol level.

At this level there is no concept of connection - instead individual packets are transmitted from one computer to another. You can think of this process as passing a note from one person to another in a room full of people: in the end the note gets to the right person, but at the same time passing through many hands.

However, there is no guarantee that the note will reach the addressee. The sender simply sends a note in the hope that it will arrive, but does not even know whether the message has arrived or not - until the recipient decides to write back.
Naturally, in reality everything is a little more complicated, since the sending computer does not know the exact sequence of computers on the network through which the packet must be transmitted so that it arrives as quickly as possible. Sometimes IP transmits multiple copies of the same packet, which may take different paths to reach the destination - and are likely to arrive at different times.

What if we want to transfer information between computers not in a file read/write style, but by directly sending and receiving individual packets?

Well, we can do this using UDP. UDP stands for “user datagram protocol” and it runs on top of IP (like TCP), but instead of adding a ton of functionality it is just a small add-on to IP.

Using UDP, we can send a packet to a specific IP address (for example, 112.140.20.10) and port (for example, 52423), and it will be transmitted from computer to computer until it reaches its destination (or gets lost along the way).

At the same time, on the receiver side we just sit and wait, listening to a certain port (52423 in our case), and when a packet arrives from someone (remember that no connections are used), we receive a notification about this with the address and port of the sending computer, packet size, and after that we can read the data from this packet.

The UDP protocol does not guarantee data delivery. In practice, most packets, of course, arrive, but there is always a loss of about 1-5%, and sometimes there are periods of time in which packets do not arrive at all (remember that between the sender and the recipient there may be thousands of computers, on any of which it may fail or break down).

Also, UDP does not guarantee the order in which packets are delivered. You can send five packets in order - 1, 2, 3, 4, 5 - but they may arrive in a completely different order - for example, 3, 1, 2, 5, 4. Again, in practice, they will most likely arrive in the correct order most of the time, but you can't rely on that!

Finally, while UDP doesn't add much to IP, it does guarantee one thing. If you forward a packet, it will either arrive completely or not at all. So, if you send a 256 byte packet to another computer, then it cannot receive only the first 100 bytes from the packet - it must receive all 256 bytes. This is really the only thing that the UDP protocol guarantees - everything else falls on your shoulders.

So we need to decide - should we use TCP or UDP sockets? Let's take a look at their properties:

  • Uses the connection principle
  • Guarantees delivery and turnaround
  • Automatically splits information into packets
  • Ensures that data is not sent too intensively (data flow control)
  • Easy to use - like writing/reading from a file
UDP:
  • Does not use the connection principle - you will have to implement it manually
  • Does not guarantee the delivery and order of delivery of packages - they may arrive in the wrong order, with duplicates, or not arrive at all!
  • You need to manually split the data into packets and send them
  • You need to be careful not to send data too intensively
  • If a packet is lost, you need to somehow track it and, if necessary, resend it
With such a list, the solution seems obvious - TCP implements all the functionality we need and is easier to use, while using UDP promises hemorrhoids with writing everything manually, from scratch. So we use TCP, right?

But no.

Using TCP is probably the worst mistake you can make when developing a multiplayer game. To understand why, let's look at what makes TCP so easy to use!

How TCP works
TCP and UDP both work on top of IP, but in reality they are completely different. UDP behaves very similarly to IP, while TCP abstracts the user away from all packet issues, making the interaction similar to reading/writing to a file.

So how does he do it?

First, TCP uses a data stream abstraction - you can simply write bytes of data to that stream, and TCP will make sure it gets to its destination. Because IP transmits data in packets and TCP runs on top of IP, TCP must break the user's input stream into individual packets. So, inside TCP, some logic collects data into a queue, and when there is enough of it, it forms a packet and sends it to the destination.

This behavior could be a problem for our multiplayer game if we need to transfer very small packets. It may happen that TCP decides not to transmit our data until it has accumulated enough to form a packet of a certain size (say, more than a hundred bytes). And this is a big problem, because it is necessary to transfer data from the client (player keystrokes) to the server as quickly as possible, and if there are delays due to data buffering by the protocol, then for the player on the client side the game will not be the most in a pleasant way. In this case, updating game objects will occur with a delay and rarely - whereas we need to update objects on time and often.

TCP has an option to fix this - “TCP_NODELAY”. It tells the protocol not to wait for the data to accumulate in the sending queue, but to send it immediately.

Unfortunately, even with this option installed, TCP has a lot of problems when used in online games.

The root of all problems lies in the way TCP handles lost or out-of-order packets, creating the illusion of a reliable and consistent connection.

How TCP ensures connection reliability
When transmitting, TCP breaks the data stream into individual packets, forwards them over the network using the unreliable IP protocol, and then reconstructs the original stream from the received packets on the receiving computer.

But what happens if one of the packets doesn't arrive? Or if the packages arrive out of order, or with duplicates?

Without delving too deeply into the details of how TCP works (and this is a really very complex topic - you can read it in TCP/IP Illustrated), the process looks like this: TCP sends a packet, determines that the packet did not arrive, and resends the same packet to the recipient. Duplicate packets are eliminated on the recipient's side, and packets that arrive out of order are reordered so that everything is as it should be - reliably and in order.

The problem is that when TCP “synchronizes” the data stream in this way, if a packet is lost, transmission stops until the lost packet is resent (and received by the destination). If new data arrives while waiting, it will be queued and you will not be able to read it until the lost packet arrives. How long does it take to resend a package? It takes at least the round-trip time of the packet (when TCP determines which packet to resend), plus the time to re-deliver the lost packet. So, if the ping between computers is 125 ms, retransmitting the packet will take about one-fifth of a second, and in the worst case, up to half a second (imagine if the resent packet suddenly gets lost too). Veselukha!

Why you should never use TCP for multiplayer games
The problem with using TCP in online games is that, unlike browsers, email, and other applications, games rely on real-time interaction. For many aspects of the game, such as the user's keystrokes and the position of the players in the game, it does not matter what happened a second ago, but only the most current state of the game world.

Let's look at a simple example of a multiplayer game, such as a 3D shooter. The network part of the game is built very simply: each iteration of the game cycle, the client sends to the server a description of all the player’s actions (keys pressed, mouse position, etc.), and each iteration the server processes this data, updates the model of the game world and sends back the current ones to the client positions of world objects so that it draws a new frame for the player.

So, in our game, if a packet is lost while being transmitted over the network, the game stops and waits until the packet is re-delivered. On the client side, game objects freeze, and on the server, players also cannot move or shoot because the server cannot accept new packets. When the lost packet finally arrives, it contains outdated information that is no longer relevant. In addition, after this, all those packets that have accumulated in the queue during the waiting time also arrive, and they all need to be processed in one iteration of the loop. Complete confusion!

Unfortunately, there is no way to change this behavior of TCP, and there is no need to, since this is the meaning of TCP. This is a necessity to make data transmission over the Internet a reliable and consistent data flow.
But we don't need a reliable and consistent data stream.

We need the data to get from the client to the server as quickly as possible, and we don't want to wait for the data to be resent.
This is why you should never use TCP for multiplayer games.

But wait! Why can't I use both UDP and TCP together?

For real-time game data, such as user clicks and game world state, only the most current data is important, but for other types of data, such as sets of commands sent from one computer to another, the reliability and consistency of the channel can be very important.

Of course, it is tempting to use UDP for user input and world state data, and TCP for data that must be guaranteed to be delivered. You may even be thinking that you could make multiple “threads” of commands - for example, one for loading levels, another for AI commands. You're thinking, “I don't need AI teams waiting in line if the data packet to load a level gets lost, because they're completely unrelated!” In this case, you are right, and you can decide to create a TCP socket for each command stream.

At first glance, this is a great idea. But the problem is that since TCP and UDP both run on top of IP, the packets of both protocols will influence each other - already at the IP level. How exactly this effect will manifest itself is a very complex question, and it is related to the reliability mechanisms in TCP. But, in any case, be aware that using TCP usually leads to increased UDP packet loss. If you want to know more about this, you can read

Good day, dear readers.
By popular demand, today I am publishing for you an article that will introduce you to the basics of computer network terms, namely:

  • Network protocols - what are these scary names and what are they used for?
  • UDP, TCP, ICMP, - what, why and what is the difference
  • IP-address, - everyone has it, but not everyone knows why this thing :-)
  • Address mask (subnet)
  • Gateway
  • A few words about routing tables
  • Ports - what they really are
  • MAC-address

Like that.

The article, I think, will be useful to everyone, young and old, because it contains not so much a set of strange, incomprehensible actions or words, but a block of information presented in accessible language, which, at a minimum, will give you an understanding of how it all works in general and why it is needed. Go.

Network protocols TCP/IP, NWLink IPX/SPX, NetBEUI

Let's start with what a network protocol is and what it is used for.
Network protocol is a set of software implemented rules for communication between computers. A kind of language in which computers talk to each other and transmit information. Previously, computers were, so to speak, multilingual and in older versions Windows a whole set of protocols was used - TCP/IP, NWLink IPX/SPX, NetBEUI. Now we have come to a general agreement, and the standard has become the use of exclusively the protocol TCP/IP, and therefore further discussion will be about him.

When they talk about TCP/IP, then this name usually means many different... rules or, say, standards that are prescribed using (or for using) this protocol. So, for example, there are rules by which messages are exchanged between mail servers and there are rules by which the end user receives letters in his mailbox. There are rules for conducting video conferences and rules for organizing “telephone” conversations over the Internet. In fact, these are not even really rules... More like a kind of grammar, or something. Well, you know, in English there is one structure for constructing dialogues, in French there is another... So in TCP/IP something similar, i.e. a certain bunch of different grammatical rules constitutes a complete protocol TCP/IP or, more precisely, TCP/IP protocol stack.

Network protocols UDP, TCP, ICMP

As part of the protocol TCP/IP protocols used for data transfer - TCP And UDP. Many people have probably heard that there are ports like TCP, so UDP, but not everyone knows what the difference is and what it is all about. So..

Data transfer via protocol TCP(Transmission Control Protocol) provides for confirmation of receipt of information. “Well, they say, did you get it? - Got it!” If the transmitting party does not receive the necessary confirmation within the established time frame, the data will be transmitted again. Therefore the protocol TCP are referred to as connection-based protocols, and UDP(User Datagram Protocol) - no. UDP used in cases where confirmation of reception is not required (for example, DNS queries or IP telephony (a prominent representative of which is Skype)). That is, the difference lies in the presence of confirmation of reception. It would seem “That’s all!”, but in practice it plays an important role.

There is also a protocol ICMP(Internet Control Message Protocol - internetworking control message protocol), which is used to transmit data about network parameters. It includes utility package types such as ping, distance unreachable, TTL etc.

What is an IP address

Everyone has one, but not everyone has an idea what kind of address this is and why it’s impossible to live without it. I'm telling you.

IP-address - 32 -x bit number used to identify a computer on the network. It is customary to write the address in decimal values ​​of each octet of this number, separating the resulting values ​​with dots. For example, 192.168.101.36

IP addresses are unique, which means that each computer has its own combination of numbers, and there cannot be two computers on the network with the same addresses. IP-addresses are distributed centrally, Internet providers make applications to national centers in accordance with their needs. The address ranges received by providers are further distributed among clients. Clients, in turn, can themselves act as a provider and distribute the received IP-addresses between subclients, etc. With this method of distribution IP-addresses, the computer system knows exactly the “location” of the computer, which has a unique IP-address; - it is enough for her to send the data to the “owner” network, and the provider, in turn, will analyze the destination and, knowing who this part of the addresses is given to, will send the information to the next owner of the subband IP-addresses until the data arrives at the destination computer.

For the construction of local networks, special address ranges are allocated. These are the addresses 10.x.x.x,192.168.x.x, 10.x.x.x, c 172.16.x.x By 172.31.x.x, 169.254.x.x, where under x- meaning any number from 0 before 254 . Packets transmitted from the specified addresses are not routed, in other words, they are simply not sent over the Internet, and therefore computers on different local networks may have matching addresses from the specified ranges. That is, in the company LLC " Horns and hooves" and LLC " Vasya and company"there may be two computers with addresses 192.168.0.244 , but they can’t, say, with addresses 85.144.213.122 , received from the Internet provider, because There can't be two identical ones on the Internet. IP-addresses. To send information from such computers to the Internet and back, special programs and devices are used that replace local addresses with real ones when working with the Internet. In other words, data is sent to the Network from a real IP-addresses, not from local ones. This process occurs unnoticed by the user and is called address translation. I would also like to mention that within the same network, say, a company, LLC " Horns and hooves", there cannot be two computers with the same local IP address, i.e., in the above example it was meant that one computer with the address 192.168.0.244 in one company, the second with the same address - in another. In the same company there are two computers with the address 192.168.0.244 they simply won't get along.

Do you want to know and be able to do more yourself?

We offer you training in the following areas: computers, programs, administration, servers, networks, website building, SEO and more. Find out the details now!

You've probably heard terms like external IP and internal IP, constant (static IP) and variable (dynamic) IP. In a nutshell about them:

  • external IP- this is exactly the same one IP, which is given to you by the provider, i.e. Your unique address on the Internet, for example, - 85.144.24.122
  • interior IP, is local IP, i.e. Your IP on a local network, for example - 192.168.1.3
  • static IP- This IP, which does not change with each connection, i.e. assigned to you firmly and forever
  • dynamic IP, is floating IP-address that changes with each connection

Your type IP(static or dynamic) depends on the provider settings.

What is an address mask (subnet)

The concept of a subnet was introduced so that we could highlight a part IP- addresses of one organization, part of another, etc. A subnet is a range of IP addresses that are considered to belong to the same local network. When working on a local network, information is sent directly to the recipient. If the data is intended for computers with an IP address that does not belong to the local network, then special rules are applied to it to calculate the route for forwarding from one network to another.

A mask is a parameter that tells the software how many computers are included in a given group (subnet). The address mask has the same structure as the IP address itself: it is a set of four groups of numbers, each of which can be in the range from 0 to 255 . In this case, the lower the mask value, the more computers are connected to this subnet. For networks of small companies, the mask usually looks like 255.255.255.x(for example, 255.255.255.224). The network mask is assigned to the computer along with the IP address. So, for example, the network 192.168.0.0 with mask 255.255.255.0 may contain computers with addresses from 192.168.0.1 before 192.168.254 192.168.0.0 with mask 255.255.255.128 allows addresses from 192.168.0.1 before 192.168.0.127 . I think the meaning is clear. As a rule, networks with a small possible number of computers are used by providers in order to save IP addresses. For example, a client may be assigned an address with a mask 255.255.255.252 . This subnet contains only two computers.

After the computer has received an IP address and knows the value of the subnet mask, the program can begin working in this local subnet. However, in order to exchange information with other computers on the global network, you need to know the rules of where to send information for the external network. For this purpose, such a characteristic as the gateway address is used.

What is a Gateway?

A gateway is a device (computer or router) that forwards information between different IP subnets. If the program determines (by IP and mask) that the destination address is not part of the local subnet, then it sends this data to the device that acts as a gateway. In the protocol settings, specify the IP address of such a device.

To work only in the local network, the gateway may not be specified.

For individual users connecting to the Internet, or for small businesses with a single connection channel, the system should have only one gateway address - this is the address of the device that has an Internet connection. If there are multiple routes, there will be multiple gateways. In this case, a routing table is used to determine the data path.

What are routing tables

And so we smoothly reached them. And so.. What kind of tables are these?

An organization or user may have several points of connection to the Internet (for example, backup channels in case something goes wrong with the first provider, but the Internet is still very necessary) or contain several IP-networks. In this case, so that the system knows which way (through which gateway) to send this or that information, routing tables are used. The routing tables for each gateway indicate those Internet subnets for which information should be transmitted through them. In this case, for several gateways you can set the same ranges, but with different costs for data transmission: for example, information will be sent over the channel that has the lowest cost, and if it fails for one reason or another, the next available most will be automatically used cheap connection.

What are network ports

When transferring data except IP-addresses of the sender and recipient, the information packet contains port numbers. Example: 192.168.1.1: 80 , - in this case 80 - this is the port number. A port is a number that is used when receiving and transmitting data to identify the process (program) that should process the data. So, if a packet is sent to 80 th port, this indicates that the information is intended for the server HTTP.

Port numbers with 1 th before 1023 -th are assigned to specific programs (so-called well-known ports). Ports with numbers 1024 -65 535 can be used in proprietary programs. In this case, possible conflicts must be resolved by the programs themselves by choosing a free port. In other words, the ports will be distributed dynamically: it is possible that the next time the program starts, it will choose a different port value, unless, of course, you manually set the port to it through the settings.

What is a MAC address

The fact is that packets sent on the network are addressed to computers not by their names and not by IP-address. The packet is intended for a device with a specific address, which is called MAC-address.

MAC address- this is the unique address of the network device, which is embedded in it by the equipment manufacturer, i.e. This is a kind of stamped number of your network card. First half MAC-address is the manufacturer's identifier, the second is the unique number of this device.

Usually MAC-address is sometimes required for identification, say, with a provider (if the provider uses a poppy address binding instead of a login-password) or when setting up a router.

Where to see all network settings

I almost forgot to say a few words about where you can look and change all this.