还在苦苦敲代码开发APP?你out啦! 试试积木搭建APP吧~

MFC Telnet Application(mfc telnet 端口,代码实现、不调用telnet.exe)

来源:codeproject     2016-05-23 16:11:20    人气:     我有话说( 0 人参与)

mfc程序telnet ip:端口,代码原生实现、不调用telnet.exe。程序源码工程升级后,可能出现编译不过的情况,请将stdafx.h中0x0410全部改为0x0501即可。

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 CClientDocCClientView pair and the server part with theCServerDocCServerView pair.

There is one additional class in the project I developed:

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.

  • 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)


MFC Telnet Application

本文源自互联网,采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可,
版权归原作者,如有问题请联系service@tsingfun.com (编辑:admin)
分享到: