Telnet的客户端如何写?请大家踊跃点 (200分)

  • 主题发起人 主题发起人 老人家
  • 开始时间 开始时间

老人家

Unregistered / Unconfirmed
GUEST, unregistred user!
Telnet的客户端如何写?/
我要针对Win2000的,针对类Unix的我有
不要用控件写,直接用winsock.pas单元的函数写
VC和Delphi的代码都行。
最好,有介绍的文章,
分不够还可以加
 
delphi好像有demo的
 
忘了告诉你我的 qq 了 84411693
 
在delphi的安装目录下的demos/indy/TelnetClient/下面有一个比较完整的例子。
 
人家说了不用控件的,我也听听!
 
void ArrangeReply(char *strOption,char* m_strResp)
{
//::MessageBox(NULL,"ArrangeReply1","",MB_OK);
unsigned char Verb;
unsigned char Option;
unsigned char Modifier;
unsigned char ch;
BOOL bDefined = FALSE;

int unsignedsites = 0;
Verb=strOption[1];
Option=strOption[2];

switch(Option)
{
case 1: // Echo
case 3: // Suppress Go-Ahead
bDefined = TRUE;
break;
}

m_strResp[unsignedsites]=IAC;
unsignedsites+=1;
if(bDefined == TRUE)
{
switch(Verb)
{
case DO:
ch = WILL;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case DONT:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WILL:
ch = DO;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WONT:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case SB:
Modifier = strOption[3];
if(Modifier == SEND)
{
ch = SB;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
m_strResp[unsignedsites]= IS;
unsignedsites+=1;
m_strResp[unsignedsites]= IAC;
unsignedsites+=1;
m_strResp[unsignedsites]= SE;
unsignedsites+=1;
}
break;
}
}
else
{
switch(Verb)
{
case DO:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case DONT:
ch = WONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WILL:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
case WONT:
ch = DONT;
m_strResp[unsignedsites]= ch;
unsignedsites+=1;
m_strResp[unsignedsites]= Option;
unsignedsites+=1;
break;
}
}
// ::MessageBox(NULL,"ArrangeReply2","",MB_OK);
}
void CloseTelnet(SOCKET *s)
{
if(*s != INVALID_SOCKET)
{
int mark=closesocket(*s);
if (mark==SOCKET_ERROR)
{
return ;
}
WSACleanup();
*s = INVALID_SOCKET;
return ;
}
}

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define BUFSIZE 1024
#define BUFSIZE1 2048
//telnet特殊标址
const unsigned char IAC = 255;
const unsigned char DO = 253;
const unsigned char DONT = 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';

看看上面代吗,大家帮帮我,要死了
 
你去看Indy的telnet控件的源代码,很详细。
 
多人接受答案了。
 
后退
顶部