Click here for larger image

Environment: VC6, NT4.0 SP3, not tested on 95 and VC5

The purpose of the TELNET Protocol is to provide a fairly general, bi-directional, eight-bit byte oriented communications facility. Its primary goal is to allow a standard method of interfacing terminal devices and terminal-oriented processes to each other. It is envisioned that the protocol may also be used for terminal-terminal communication ("linking") and process-process communication (distributed computation).GENERAL CONSIDERATIONS A TELNET connection is a Transmission Control Protocol (TCP) connection used to transmit data with interspersed TELNET control information. The TELNET Protocol is built upon three main ideas: first, the concept of a "Network Virtual Terminal"; second, the principle of negotiated options; and third, a symmetric view of terminals and processes.

When a TELNET connection is first established, each end is assumed to originate and terminate at a "Network Virtual Terminal", or NVT. An NVT is an imaginary device which provides a standard, network-wide, intermediate representation of a canonical terminal. This eliminates the need for "server" and "user" hosts to keep information about the characteristics of each other's terminals and terminal handling conventions. All hosts, both user and server, map their local device characteristics and conventions so as to appear to be dealing with an NVT over the network, and each can assume a similar mapping by the other party. The NVT is intended to strike a balance between being overly restricted (not providing hosts a rich enough vocabulary for mapping into their local character sets), and being overly inclusive (penalizing users with modest terminals).

This Project has several main classes


CSocketDx Class is used to establish TCP connection. In addition to the constructor and destructor it has 3 functions:

  • CSocketDx(char *,int);
  • ~CSocketDx();
  • int Create();
  • int Connect();
  • SOCKET TelnetConnect();


CSocketRx Class is used to receive data. It has only one thread.

  • CSocketRx();
  • CSocketRx(SOCKET,HANDLE&);
  • virtual ~CSocketRx();
  • static DWORD RdTh(CSocketRx *);


CSocketTx Class is used to send data. It has only one thread.

  • CSocketTx(SOCKET,HANDLE&);
  • virtual ~CSocketTx();
  • static DWORD SendTh(CSocketTx*);


CProtocolRx Class is used to implement Telnet protocol.

inline void yesreply(SOCKET server, _verb verb,_option option);
inline void noreply(SOCKET server, _verb verb,_option option);
inline void askfor(SOCKET server, _verb verb,_option option);
void TelentProtcol(SOCKET server,unsigned char code);


Download source - 42 Kb


  • telnet

    Posted by Legacy on 09/04/2003 12:00am

    Originally posted by: sambasivarao


    i did not understand aim of this project.
    can any body help me.
    what it does.

    just in 2 there any need of any hardware devices.


  • code use in linux ?

    Posted by Legacy on 03/15/2003 12:00am

    Originally posted by: jiali

    Can you tell me where i could find any simple c code that could used in linux?
    I just want to use the telnet protocol to send serval commands to do some works automatically.

  • difference...

    Posted by Legacy on 03/05/2003 12:00am

    Originally posted by: Thirumalai

    can u tell me the differece between ur Telnet console application and previous Telnet Protocol which is normally using in Linux/unix

  • poor quality...

    Posted by Legacy on 01/09/2003 12:00am

    Originally posted by: Ole Dole Doff

    While looking the web for a telnet implementation I came across this code. I'm sad to say but the quality of this piece of code is very poor. I could not find many others and the few ones I found was either part of a more complex product and hard to extract or either of poor quality too

    However, use this piece of code to see the principle for how to implement a telnet-state machine yourself. And read the books by W. Richard Stevens, Douglas Comer and Jon Snader.


    Sorry Ibrar...

  • internet & networking Telnet - Ibrar Ahmad

    Posted by Legacy on 09/23/2002 12:00am

    Originally posted by: Klaus Scheibe

    Well done, Ibrar. Your code is fairly readable and worth reading. I am very in favor of it. I took the underlying idea and rewrote your program in C / Linux and C / HP-UX.

    Did you keep on development ?
    Do you meanwhile support other teminals ?

  • ANSI implementation flaws

    Posted by Legacy on 05/26/2002 12:00am

    Originally posted by: QShot

    Hey excellent job on the telnet client. However the ansi implementation isn't very robust. I had to fix up a few things for it to work (&look) right with pine. These fixes should eliminate most problems people are seeing with your code.

    *Problem level: annoying
    1.) added initialization of
    to ansi_set_screen_attribute.

    *Problem level: annoying
    2.) added
    to ansi_erase_screen & ansi_erase_line

    *Problem level: annoying
    3.) Also, the client wasn't sending arrow keys correctly? I had to convert the input from getch() so that it would send
    ESC A, ESC B, ESC C, ESC D instead of 224 H, 224 K, 224 M, 224 P

    *Problem level: Very Bad
    4.) Pine kept sending ESC[@ so I had to change the DataProc for ansi so that the asc_esc1 state checked for
    if (data >= 64)



  • Creating server

    Posted by Legacy on 05/20/2002 12:00am

    Originally posted by: Devan Lippman

    Can I use this to create a telnet server?

  • missing chars

    Posted by Legacy on 05/08/2002 12:00am

    Originally posted by: TTS


    I am able to compile and test your client. I do notice that 1st char is always truncated when receiving from the server. For example, when the server was sending 'Passowrd', the client only received 'assword'. Do you have any idea why ?? I kind of looking at the code but because it uses state machine, It is difficult to debug ?


  • Console code

    Posted by Legacy on 04/03/2002 12:00am

    Originally posted by: Michael

    I would expect, but don't know for sure, that the console (conio.h) code is what is failing on Win98 particularly if you developed it under WinNT/2K/XP. This was a trap I fell into on one of my projects. I believed the MSDN docs that said conio worked reliably across DOS and NT. They don't work 100% the same.

    I'll try it out on my Win98 machine when I get a free minute.


    Posted by Legacy on 03/21/2002 12:00am

    Originally posted by: DaWiZARD


  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As the mobile enterprise marketplace expands and customer needs grow more diverse, Samsung recognizes that solution partners and developers play an essential role by continually innovating to meet their customers' needs. Samsung works to provide these developers and partners with the latest tools and resources needed to create these solutions. Read this program guide to learn how the Samsung Enterprise Alliance Program provides partners and developers with Samsung enterprise software development kits (SDKs) …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date