本文介绍了与 telnet 客户端协商回声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我想为标准 Telnet 应用程序创建一个服务器作为要连接的客户端.我用 C++ 写了一个基本的 TCP 服务器,它的目的是提供一个交互式菜单,所以我必须在我这边设置 ECHO.

For some reason, I want to create a server for the standard Telnet application as client to connect to. I wrote a basic TCP server in C++, its purpose is to serve an interactive menu, so I have to set ECHO on my side.

当客户端连接时,我向它发送IAC WILL ECHO,我希望得到IAC DO ECHO.令我惊讶的是,我得到的是IAC DO ECHOIAC WON'T ECHOIAC DON'T ECHO.三个消息一一.并且客户端还在自己回声.

When the client connects, I send IAC WILL ECHO to it, and I expected to get IAC DO ECHO. To my surprise, what I get is IAC DO ECHO, IAC WON'T ECHO, IAC DON'T ECHO. Three messages one by one. And the client is still echoing by itself.

我做错了什么?这三个消息是什么意思?

What am I doing wrong? What do those three messages mean?

int main() {
    TcpListener tcpListener(10001);  // custom tcp helper library
    auto stream = tcpListener.acceptClient();
    vector<uint8_t> msg = {255, 251, 1}; // send IAC WILL ECHO on start
    stream.writeBytes(msg);
    auto message = stream.readBytes(100);
    while (!message.empty()) {
        for (auto c : message) cout << (int)c << endl; // to see what i'm getting from client
        cout << "length: " << message.size() << "\n";
        stream.writeBytes(message); // echo back
        message = stream.readBytes(100);
    }
    return 0;
}

推荐答案

我认为我的错误现在可以在我的代码中看到,但我做了一些更复杂的版本.问题是我回显了来自客户端的所有消息,所以当我发送 IAC WILL ECHO 时,它以 IAC DO ECHO 响应.当我回应它时,客户说它不会这样做,然后发送 IAC DON'T ECHO(以清除我认为的情况).所以当然要避免这样的错误,telnet服务器首先要做的就是正确处理协商.

I think my mistake can be now seen in my code, but I worked on some more complicated version of it. The problem is I echoed all messages from client, so when I sent IAC WILL ECHO it responded with IAC DO ECHO. When I echoed it client said it won't do it and then sent IAC DON'T ECHO (to clear the situation I think). So of course to avoid such errors first thing in telnet server is to properly handle negotation.

这篇关于与 telnet 客户端协商回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 18:28