Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC
Article

MFC Telnet Application

Rate me:
Please Sign up or sign in to vote.
3.70/5 (12 votes)
8 Nov 2007GPL32 min read 70.9K   5.6K   26   9
The article demonstrates an MFC GUI Telnet application with server capabilities for incoming connections support.

Introduction

I've developed a Telnet application for implementing manual connection and data sending capabilities to Internet servers. You may use it for text mode Internet protocols (SMTP, POP, HTTP, WHOIS etc.) for sending, retrieving emails, whois queries, and so on. The application also allows opening ports on local computers for incoming connections.

Background

You need an understanding of Internet protocols to be able to connect to servers and implement commands. Have a look at the corresponding RFCs available online.

Using the code

Click the first red button on the toolbar (CTRL+N) to connect to an Internet server on a particular port.

connect to server

The server address combo box is filled with predefined addresses, loaded from a hosts file present in the same directory as the Telnet application. After being connected to the server, you may send text messages to it. Click the INS key button in the text view, type in the command you want to send (if it won't fit in one single line, press ENTER to move the caret to the next line; also, in the multi-line text messages, end the last string you typed with an ENTER, and press ESC to send it), then press the ESC key to send the data you typed in. Wait for the response from the server.

This one provides an example output of a whois query on port 43:

whois query

whois query

In case of getting disconnected, press CTRL+R to redial connection to that server.

To listen on a particular port, press CTRL+L and enter the port you want to open:

listen on port

Try to open port 80 and enter http://127.0.0.1 in your IE browser while disconnected from the Internet. You will get a message similar to that appearing in the text view. You may send a reply to the IE browser with the same mode as I described before (INS, type the text message, ENTER, ESC).

IE connection

The client part is implemented with the CClientDoc, CClientView pair and the server part with the CServerDoc, CServerView pair.

There is one additional class in the project I developed:

  • Socket
  • It actually wraps WinSock functions for creating a socket, connecting to the server, sending and receiving data, and listening on a port. Have a look at the socket.h header.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Engineer
Russian Federation Russian Federation
Highly skilled Engineer with 14 years of experience in academia, R&D and commercial product development supporting full software life-cycle from idea to implementation and further support. During my academic career I was able to succeed in MIT Computers in Cardiology 2006 international challenge, as a R&D and SW engineer gain CodeProject MVP, find algorithmic solutions to quickly resolve tough customer problems to pass product requirements in tight deadlines. My key areas of expertise involve Object-Oriented
Analysis and Design OOAD, OOP, machine learning, natural language processing, face recognition, computer vision and image processing, wavelet analysis, digital signal processing in cardiology.

Comments and Discussions

 
GeneralERROR - Your telnet client rejected our request to use char-at-a-time mode! Pin
Member 223391512-Oct-09 17:54
Member 223391512-Oct-09 17:54 
AnswerRe: ERROR - Your telnet client rejected our request to use char-at-a-time mode! Pin
Chesnokov Yuriy12-Oct-09 19:09
professionalChesnokov Yuriy12-Oct-09 19:09 
QuestionHow to get whois query output? Pin
Priya_Sundar30-Oct-08 22:30
Priya_Sundar30-Oct-08 22:30 
AnswerRe: How to get whois query output? Pin
Chesnokov Yuriy31-Oct-08 1:13
professionalChesnokov Yuriy31-Oct-08 1:13 
QuestionHow to add the source code in project? - No .dsp or .dsw files. Pin
Priya_Sundar29-Oct-08 20:06
Priya_Sundar29-Oct-08 20:06 
AnswerRe: How to add the source code in project? - No .dsp or .dsw files. Pin
Chesnokov Yuriy29-Oct-08 20:22
professionalChesnokov Yuriy29-Oct-08 20:22 
GeneralRe: How to add the source code in project? - No .dsp or .dsw files. Pin
Priya_Sundar30-Oct-08 18:42
Priya_Sundar30-Oct-08 18:42 
Hi,

After making a lot of changes i got the project finally executed.

1. Convert the VC++7.0 .vcproj to .dsp file using the VC++7 to VC++6 project converter[^]

2. Declare #define _WSPIAPI_COUNTOF above #include <Ws2tcpip.h> in stdafx.h file
#define _WSPIAPI_COUNTOF
#include <Ws2tcpip.h>

3. In project settings, add the three library files - MsWSock.Lib WSock32.Lib Ws2_32.lib in the link tab.

4. Change all the occurances of the CArray<byte> to CArray<byte,byte>;
Change GetCount to GetSize;
CString AppenChar function is not supported, you could directly assign it to the buffer.

Probably this would help for the future users.

Priya Sundar

Generalgood work. can u send to me.full source plz.. Pin
ox1111@paran.com25-May-08 18:11
ox1111@paran.com25-May-08 18:11 
AnswerRe: good work. can u send to me.full source plz.. it's in src.zip Pin
Chesnokov Yuriy26-May-08 20:57
professionalChesnokov Yuriy26-May-08 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.