telnet.h
来自「vt100终端仿真程序」· C头文件 代码 · 共 193 行
H
193 行
// Telnet.h: interface for the CTelnet class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TELNET_H__F8B8D3EA_C3DD_4711_B2E9_6D7E4DFCF484__INCLUDED_)
#define AFX_TELNET_H__F8B8D3EA_C3DD_4711_B2E9_6D7E4DFCF484__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "winsock.h"
#include "Communicate.h"
#include "cfgfile.h"
//#include "maketyp.h"
extern int iTrace;
extern HWND hOutWnd;
extern int iTermNo;
class CTelnet : public CCommunicate
{
public:
CTelnet();
virtual ~CTelnet();
virtual int InitCom()
{
WSADATA WSAData;
struct sockaddr_in ServerAddr;
char szIp[20];
TCHAR wcIp[20],wcTitle[40];
int iPortNum,iRet;
CCfgFile csCfgFile;
if (m_pOwnerWnd==NULL){
return 1;
}
if(m_blIsRcvThreadActive||m_blIsSndThreadActive)
return 0;
//Get parameter from config file
m_iTermNo=iTermNo;
memset(wcIp,0,sizeof(wcIp));
iRet=csCfgFile.GetCfgItemStr(IPADD,wcIp,16);
if(iRet<=0)
return 7;
memset(szIp,0,sizeof(szIp));
while(iRet>0){
szIp[iRet-1]=(char)wcIp[iRet-1];
iRet--;
}
iPortNum=csCfgFile.GetCfgItemInt(PORTNUM);
if (WSAStartup(MAKEWORD(1,1), &WSAData)!=0){
return 2;
}
//create socket
ServerAddr.sin_family=AF_INET;
ServerAddr.sin_addr.s_addr=inet_addr(szIp);
ServerAddr.sin_port=htons(iPortNum);
ServerAddrSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(ServerAddrSocket<0) {
return 3;
}
if(connect(ServerAddrSocket,(LPSOCKADDR)&ServerAddr,sizeof(ServerAddr))==SOCKET_ERROR) {
closesocket(ServerAddrSocket);
return 4;
}
//create stop evnet
/* m_hStopEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
//create send request event
m_hSendDataEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
*/
m_blIsRcvThreadActive=FALSE;
m_blIsSndThreadActive=FALSE;
//create Rcv thread
DWORD dwRcvId;
if((m_pRcvThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)RcvThread,this,0,&dwRcvId))==NULL){
return 5;
}
//create Snd thread
/* DWORD dwSndId;
if(CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)SndThread,this,0,&dwSndId)==NULL){
return 6;
}
*/
//wait until started
while(!m_blIsRcvThreadActive){
Sleep(10);
}
/* while(!m_blIsSndThreadActive){
Sleep(10);
}
*/
memset(wcTitle,0,sizeof(wcTitle));
wcscpy(wcTitle,TEXT("美斯比VT100仿真终端---"));
wcscat(wcTitle,wcIp);
wsprintf(wcTitle+wcslen(wcTitle),TEXT(":%d"),m_iTermNo);
SetWindowText(hOutWnd,wcTitle);
return 0;
}
virtual int ResetCom()
{
// MSG message;
//Send Stop signal to SndThread
/* if(m_hStopEvent!=NULL){
SetEvent(m_hStopEvent);///触发事件
while(m_blIsSndThreadActive==TRUE)
if(::PeekMessage(&message,NULL,0,0,PM_REMOVE)){
::TranslateMessage(&message);
::DispatchMessage(&message);
}
CloseHandle(m_hStopEvent);
m_hStopEvent=NULL;
}
*/
//close comm handle
if(ServerAddrSocket!=NULL){
closesocket(ServerAddrSocket);
ServerAddrSocket=NULL;
}
//kill RcvThread
if(m_blIsRcvThreadActive==TRUE){
TerminateThread(m_pRcvThread,0);
m_blIsRcvThreadActive=FALSE;
}
return 0;
}
virtual int SendData(char *pszSendBuf,int iLen)
{
char szTemp[100];
int iRet;
memset(m_szSendBuf,0,sizeof(m_szSendBuf));
memcpy(m_szSendBuf,pszSendBuf,iLen);
m_dwSendLen=iLen;
// csLog.WriteLog(1,0,m_szSendBuf,m_dwSendLen);
if((iRet=send(ServerAddrSocket,m_szSendBuf,m_dwSendLen,0))<=0){
sprintf(szTemp,"Snd Error,error code=%d",GetLastError());
// csLog.WriteLog(1,0,szTemp,0);
return 1;
}
else{
// csLog.WriteLog(1,0,m_szSendBuf,iRet);
//SetEvent(m_hSendDataEvent);
}
return 0;
}
private:
int m_iTermNo;
int Trans(char *pszSrc,char *pszDes);
int GetUserPwd(char *pszUserPwd);
int GetUserId(char *pszUserId);
static UINT RcvThread(LPVOID pParam);
static UINT SndThread(LPVOID pParam);
// int RcvData(char *pszDataBuf,DWORD *pdwLen);
int Negotiate();
BOOL m_blNeg;
SOCKET ServerAddrSocket;
protected:
int LogOn();
BOOL m_blLogonOk;
};
#endif // !defined(AFX_TELNET_H__F8B8D3EA_C3DD_4711_B2E9_6D7E4DFCF484__INCLUDED_)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?