3.4.2 具体实现(2)
(4) 在文件CTelnetView.h中实现CTelnetView类的编写,具体代码如下:
- class CTelnetDoc;
- class CClientSocket;
- //下一个bit组为命令
- const unsigned char IAC = 255;
- //作为一种请求发送给另一方来启动某个选项
- const unsigned char DO = 253;
- //响应保证是连接最终保持与这种没有任何选项的状态
- const unsigned char DON’T = 254;
- //表示发送或接收一方希望执行某个选项
- const unsigned char WILL = 251;
- //响应保证是连接最终保持与这种没有任何选项的状态
- const unsigned char WONT = 252;
- //开始选项协商
- const unsigned char SB = 250;
- //选项协商结束
- const unsigned char SE = 240;
- //判断标识
- const unsigned char IS = '0';
- const unsigned char SEND = '1';
- const unsigned char INFO = '2';
- const unsigned char VAR = '0';
- const unsigned char VALUE = '1';
- const unsigned char ESC = '2';
- const unsigned char USERVAR = '3';
-
- #define bufferLines 30
- #define dtX 8
- #define dtY 13
- //设置输入输出缓冲区的大小为1024KB
- #define ioBuffSize 1024
-
- class CTelnetView : public CScrollView
- {
- protected: // create from serialization only
- CTelnetView();
- DECLARE_DYNCREATE(CTelnetView)
-
- COLORREF cTextColor;
- COLORREF cBackgroundColor;
-
- CString cHostName;
- //定义并声明和远程访问相关的变量和方法
- public:
- CClientSocket *cSock;
- void ArrangeReply(CString strOption);
- //正常传输的字符串
- CString m_strNormalText;
- //选择响应方法
- void RespondToOptions();
- //处理信息流程的方法
- void ProcessOptions();
- //设置临时计数器
- int TempCounter;
- //字符串选择
- CString m_strOptions;
- //字符串行表选择
- CStringList m_ListOptions;
- //协商标识变量
- BOOL bNegotiating;
- BOOL bOptionsSent;
- CString m_strResp;
- CString m_strLine;
- unsigned char m_bBuf[ioBuffSize];
- BOOL GetLine(unsigned char *bytes, int nBytes, int &ndx);
- void DispatchMessage(CString strText);
- void ProcessMessage(CClientSocket *cSocket);
-
- char cText[100][bufferLines];
- long cCursX;
- CString m_strline;
- //绘制清除窗口
- void DrawCursor(CDC *pDC, BOOL pDraw);
- void DoDraw(CDC *pDC);
- void ClearWindows(CDC *pDc);
- //当前的坐标
- int CurrentXX;
- int CurrentYY;
-
- //测试程序