Python telnet 与原始 tcp 连接有何不同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12730293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:43:28  来源:igfitidea点击:

How does telnet differ from a raw tcp connection

pythonsocketsnetwork-programmingtelnet

提问by Pradyot

I am trying to send commands to a server via a python script. I can see the socket connection being established on the server. But the commands I am sending across , do not seem to make it through(server does a read on the socket). The server currently supports a telnet command interpreter. ie: you telnet to the command address and port, and you can start sending string commands. My question is , is there anything fundamentally different from sending strings over a tcp socket, as opposed to using telnet. I have used both raw sockets as well as the Twisted framework.

我正在尝试通过 python 脚本向服务器发送命令。我可以看到正在服务器上建立的套接字连接。但是我发送的命令似乎没有通过(服务器读取套接字)。服务器当前支持 telnet 命令解释器。即:您 telnet 到命令地址和端口,并且您可以开始发送字符串命令。我的问题是,与使用 telnet 相比,通过 tcp 套接字发送字符串有什么根本不同。我使用过原始套接字和 Twisted 框架。

采纳答案by Brian White

Telnet is a way of passing control information about the communication channel. It defines line-buffering, character echo, etc, and is done through a series of will/wont/do/dont messages when the connection starts (and, on rare occasions, during the session).

Telnet 是一种传递有关通信通道的控制信息的方式。它定义了行缓冲、字符回显等,并在连接开始时(并且在极少数情况下,在会话期间)通过一系列 will/wont/do/dont 消息完成。

That's probably not what your server documentation means. Instead, it probably means that you can open a TCP socket to the port using a program like "Telnet" and interact with a command interpreter on the server.

这可能不是您的服务器文档的意思。相反,这可能意味着您可以使用“Telnet”等程序打开端口的 TCP 套接字并与服务器上的命令解释器交互。

When the Telnet program connects, it typically listens for these control messages before responding in kind and so will work with TCP/socket connections that don't actually use the telnet protocol, reverting to a simple raw pipe. The server must do all character echo, line buffering, etc.

当 Telnet 程序连接时,它通常会在做出响应之前侦听这些控制消息,因此将与实际上不使用 telnet 协议的 TCP/socket 连接一起工作,恢复到简单的原始管道。服务器必须执行所有字符回显、行缓冲等。

So in yourcase, the server is likely using a raw TCP stream with no telnet escape sequences and thus there is no difference.

因此,在您的情况下,服务器可能使用没有 telnet 转义序列的原始 TCP 流,因此没有区别。

回答by ecbrodie

Keep in mind that Telnet is an application layerprotocol while TCP is a transport layerprotocol. Telnet usesTCP in order to transmit data. That is a big fundamental difference between Telnet and TCP.

请记住,Telnet是一种应用层协议,而TCP是一个传送层协议。Telnet使用TCP 来传输数据。这是 Telnet 和 TCP 之间一个很大的根本区别。

See:OSI Model wikipedia page

请参阅:OSI 模型维基百科页面

回答by simonc

From the Wikipedia pageon telnet

从telnet 上的维基百科页面

...User data is interspersed in-band with Telnet control information...

...用户数据与 Telnet 控制信息在带内散布...

So, to answer your question, yes, telnet does differ from a raw socket.

因此,要回答您的问题,是的,telnet 确实与原始套接字不同。

RFC 854describes the telnet protocol if you want to try implementing it or you could use telnetlibif you'd prefer an existing python client.

RFC 854描述了 telnet 协议,如果你想尝试实现它,或者如果你更喜欢现有的 python 客户端,你可以使用telnetlib