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.
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;
}