6 Answers
6

For very basic telnet (just telnet to a port and echo bytes), there's not much to do. Read from a socket, process it (in an echo server, do nothing), spit back a result. You could implement a simple MUD-style server without knowing anything in any RFCs.

But if you're really concerned about RFCs, RFC 854 might be a starting point.

This answer is incorrect. For basic telnet to work connection establishment (which involves option negotiation) has to happen. A bunch of telnet protocol commands have to be working before a server will get to stage of prompting user for login/password/commands. This sequence diagram shows what happens: eventhelix.com/realtimemantra/networking/Telnet.pdf
–
gaoitheMay 25 at 10:54

Note that real telnet is not just a simple interface that handles the stdin and stdout of the user's login shell.

There's lots of additional functionality that is carried separately in 'options', which handle such things as setting the $TERM environment variable, setting the rows/columns (and resetting them if the user resizes their terminal).

If you are looking to do real telnet, and not just a simple TCP server, then indeed RFC 854 is your starting point. However there's stacks more relevant RFCs which describe those options mentioned above which are listed at http://en.wikipedia.org/wiki/Telnet

Knowing how the socket API works internally is very useful, because it is often exported with very minor changes by higher level languages.

That said, you might want to use the event loop support provided by GLib and use the related networking library GNet.

Here's how to use GNet to open a socket on port 4000, then close every connection made to it. There is a little bit of magic here as the server registers itself with the default main context as part of its creation.

I recommend installing Wireshark to watch the Telnet traffic using an existing Telnet server. Then looking at the log, you can gain a better understanding of how the server communicates with the client. Then, use the RFC as a reference if you don't understand any of the commands going across the wire.