plus to tcp/socket programming, you must understand how telnet protocol works, for that you can refer to RFC(request for comment) documents
this is telnet specification telnet specification
and old telnep protocol rfc
for very pure delphi telnet client/daemon code please check this pack (KOL based)