Telnet protocol introduction...

Source: Internet
Author: User
Tags printable characters
1. Basic Content

The telnet protocol is a member of the TCP/IP protocol family and is the standard protocol for the Internet remote login service. The telnet protocol can be used to convert the computer used by the local user into a terminal of the remote host system. It provides three basic services:

1) Telnet defines a network virtual terminal to provide a standard interface for a remote system. ClientProgramWithout having to know more about distant systems, they only need to construct programs that use standard interfaces;

2) Telnet includes a mechanism that allows the client and server to negotiate options, and it also provides a set of standard options;

3) Telnet performs symmetric processing on the two ends of the connection. That is, Telnet does not force the client to input data from the keyboard or display the output on the screen.

2. Heterogeneous adaptation

To make Telnet interaction between multiple operating systems possible, you must have a detailed understanding of heterogeneous computers and operating systems. For example, in some operating systems, each line of text needs to end with an ASCII carriage return controller (CR), and in other systems, an ASCII Line Break (LF) is required ), there are also some systems that need to use a two-character sequence carriage return-line feed (CR-LF); for example, most operating systems provide users with a shortcut to interrupt the program, however, this shortcut key may vary across systems (some systems use Ctrl + C, while others use escape ). If the heterogeneity between systems is not considered, the characters or commands sent locally may be inaccurate or cause errors after being transferred to the remote and interpreted by the remote system. Therefore, the Telnet protocol must solve this problem.

To adapt to heterogeneous environments, the Telnet protocol defines the transmission mode of data and commands over the Internet. This definition is called the network virtual terminal nvt (net virtual terminal ). Its application process is as follows:

For the sent data: the client software converts the buttons and command sequences from the user terminal to the nvt format and sends them to the server. The server software will receive the data and commands, convert the nvt format to the format required by the remote system;

For returned data: the remote server converts the data from the remote server to the nvt format, while the local client then converts the received nvt format data to the local format.

If you are interested in the detailed definition of the nvt format, you can find the relevant information.

3 Send remote commands

We know that most operating systems provide various shortcut keys to implement corresponding control commands. When you type these shortcut keys on a local terminal, the local system will execute the corresponding control commands, instead of using these shortcut keys as input. So for telnet, what does it use to implement remote transmission of control commands?

Telnet also uses nvt to define how control functions are transmitted from the client to the server. We know that the usascii character set includes 95 printable characters and 33 control codes. When you type a common character locally, nvt transmits it according to its original meaning. When you type a shortcut key (key combination, nvt transfers it to a special ASCII character over the network and converts it to the corresponding control command after it reaches the remote machine. There are two main reasons for distinguishing the normal ASCII character set from the control command:

1) this distinction means that Telnet has greater flexibility: It can transmit all possible ASCII characters and all control functions between the client and the server;

2) This distinction allows the client to have no ambiguity-specific signaling, without confusion between the control function and common characters.

4. Data Flow

As mentioned above, designing Telnet as an application-level software has one disadvantage: low efficiency. Why? The following shows the data flow in telnet:

The data is typed by the user on the local keyboard and transmitted to the client program through the operating system. The client program processes the data and returns the data to the operating system. The data is transmitted over the network to the remote machine, the remote operating system sends the received data to the server program, and the server program processes the data again. Then, the system returns the Pseudo Terminal entry point on the operating system. Finally, the remote operating system transmits data to the application that the user is running. This is a complete input process, and the output is transmitted from the server to the client according to the same path.

Because the computer switches the process environment several times for each input and output, this overhead is very expensive. Fortunately, the user's input speed is not high. We can still accept this disadvantage.

5. Force Command

We should consider this situation: assume that the local user runs an endless loop of error commands or programs on the remote machine, and the command or program has stopped reading input, therefore, the buffer of the operating system may be full. In this case, the remote server cannot write data to the Pseudo Terminal and eventually stop reading data from the TCP connection, the buffer of the TCP connection will eventually be full, thus blocking the flow of data streams into the connection. If this happens, the local user will lose control of the remote machine.

To solve this problem, the Telnet protocol must use the out-of-band signaling to force the server to read a control command. We know that TCP uses an emergency data mechanism to implement out-of-band data signaling, so Telnet only needs to append a retained eight-bit group called date mark, then, the server can be notified by sending a packet segment with an emergency data bit over TCP. The packet segment carrying the emergency data will bypass the traffic control and directly reach the server. As a response to emergency signaling, the server reads and discards all data until a data mark is found. After the server encounters a data mark, it returns a normal processing process.

6 Option Negotiation

Due to the heterogeneity of the machines and operating systems at the two ends of Telnet, it is impossible for telnet to strictly specify the detailed configuration of each Telnet connection. Otherwise, the adaptability and heterogeneity of Telnet will be greatly affected. Therefore, Telnet adopts the option negotiation mechanism to solve this problem.

The range of Telnet options is wide: some options extend the general functions, while some options involve some minor details. For example, there is an option to control whether Telnet works in half-duplex or full-duplex mode (in the big direction); there is also an option to allow servers on remote machines to determine the user terminal type (small details ).

The negotiation method of the telnet option is also very interesting. It is symmetric for each option, that is, any end can send a negotiation application; any end can accept or reject this application. In addition, if one end tries to negotiate options that the other end does not know, the one end that accepts the request can simply refuse the negotiation. Therefore, updates and more complex versions of the Telnet client server may interact with older and less complex versions. If both the client and server understand the new options, the interaction may be improved. Otherwise, they will run together in a less efficient but workable manner. All these designs aim to enhance the adaptability to heterogeneity. We can see how important it is to the application and development of Telnet.

Some principles have been discussed above. Although it is difficult for us to access this layer during the use of Telnet, I think it makes sense to understand this layer, it will give us a lot of inspiration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.