Telnet服务器如何与客户端通信?

时间:2021-04-20 00:19:18

I want to write a C# application where it connects to a telnet server and communicates to the server. I was wondering how a telnet server sends information to the client. I have looked (skimmed) over the Telnet RFC and looked at the incoming packets coming in from the server and still a bit confused. Can somebody give me an example how the server moves the cursor around in the telnet client and how it can change colors of characters? (An example would be most appreciated)

我想编写一个C#应用程序,它连接到telnet服务器并与服务器通信。我想知道telnet服务器如何向客户端发送信息。我看过(浏览过)Telnet RFC并查看从服务器进来的传入数据包,但仍然有点困惑。有人能给我一个例子,说明服务器如何在telnet客户端中移动光标以及它如何改变字符的颜色? (最值得赞赏的一个例子)

Update I

Here's some additional VT100 resources:

这是一些额外的VT100资源:

  1. ANSI/VT100 Terminal Control
  2. ANSI / VT100终端控制

  3. vt100_codes_news.txt

Update II

With much research and time, here what I found out: Telnet Programming with C#

经过大量的研究和时间,我发现了这一点:使用C#进行Telnet编程

3 个解决方案

#1


7  

Moving the cursor and changing the color isn't done by the telnet protocol.

移动光标并更改颜色不是由telnet协议完成的。

Your telnet client is emulating a terminal, most probably a VT-100 variant. To move the cursor and change the color, the server sends escape sequences especific to the type of terminal being emulated (which one is sent in the telnet protocol negotiation).

您的telnet客户端正在模拟终端,很可能是VT-100变体。要移动光标并更改颜色,服务器会发送转义序列,特别是要模拟的终端类型(哪一个是在telnet协议协商中发送的)。

If you don't want these escape sequences, telling the server on the telnet protocol negotiation you are a "dumb" terminal should be enough. If you want them (or if the server assumes everyone has a VT-100 and always sends them) you will have to implement a VT-100 terminal emulator (or at least enough of it to discard what you don't want).

如果你不想要这些转义序列,告诉服务器telnet协议协商你是一个“哑”终端应该就够了。如果你想要它们(或者如果服务器假设每个人都有VT-100并且总是发送它们),你将不得不实现VT-100终端模拟器(或者至少足以丢弃你不想要的东西)。

#2


2  

A simple Google search reveals many open source Telnet (and other network protocol) clients written in C#. You could just download the source code to one and see how they implement connection negotiation and commands.

一个简单的谷歌搜索揭示了许多用C#编写的开源Telnet(和其他网络协议)客户端。您可以将源代码下载到一个,看看它们如何实现连接协商和命令。

#3


2  

With respect to handling the cursor and text colours, etc., now you are talking about terminal emulation. For that you will need a library. This looks like a good place to start.

关于处理光标和文本颜色等,现在你谈论终端仿真。为此你需要一个图书馆。这看起来是个好地方。

#1


7  

Moving the cursor and changing the color isn't done by the telnet protocol.

移动光标并更改颜色不是由telnet协议完成的。

Your telnet client is emulating a terminal, most probably a VT-100 variant. To move the cursor and change the color, the server sends escape sequences especific to the type of terminal being emulated (which one is sent in the telnet protocol negotiation).

您的telnet客户端正在模拟终端,很可能是VT-100变体。要移动光标并更改颜色,服务器会发送转义序列,特别是要模拟的终端类型(哪一个是在telnet协议协商中发送的)。

If you don't want these escape sequences, telling the server on the telnet protocol negotiation you are a "dumb" terminal should be enough. If you want them (or if the server assumes everyone has a VT-100 and always sends them) you will have to implement a VT-100 terminal emulator (or at least enough of it to discard what you don't want).

如果你不想要这些转义序列,告诉服务器telnet协议协商你是一个“哑”终端应该就够了。如果你想要它们(或者如果服务器假设每个人都有VT-100并且总是发送它们),你将不得不实现VT-100终端模拟器(或者至少足以丢弃你不想要的东西)。

#2


2  

A simple Google search reveals many open source Telnet (and other network protocol) clients written in C#. You could just download the source code to one and see how they implement connection negotiation and commands.

一个简单的谷歌搜索揭示了许多用C#编写的开源Telnet(和其他网络协议)客户端。您可以将源代码下载到一个,看看它们如何实现连接协商和命令。

#3


2  

With respect to handling the cursor and text colours, etc., now you are talking about terminal emulation. For that you will need a library. This looks like a good place to start.

关于处理光标和文本颜色等,现在你谈论终端仿真。为此你需要一个图书馆。这看起来是个好地方。