看看这个
function TelnetConn(var m_Socket: TSocket; Login: TTelnetLogin): Integer;
var
WSAData1: WSAData;
ServerTelnet: sockaddr_in;
nReturn: Integer;
Waittime: linger;
begin
WSAStartup(wVersionRequested, WSAData1);
m_Socket := INVALID_SOCKET;
ServerTelnet.sin_family := AF_INET;
ServerTelnet.sin_addr.s_addr := inet_addr(Login.IP);
ServerTelnet.sin_port := htons(Login.TelPort);
m_Socket := socket(AF_INET, SOCK_STREAM , 0);
nReturn := connect(m_Socket ,ServerTelnet, sizeof(sockaddr_in));
if nReturn = SOCKET_ERROR then
//ShowMessage('Network connenct error')
else
begin
Waittime.l_linger := 5;
Waittime.l_onoff := WORD(True);
setsockopt(m_Socket, SOL_SOCKET, SO_RCVTIMEO, PChar(TimeOut), sizeof(TimeOut));
setsockopt(m_Socket, SOL_SOCKET, SO_LINGER, PChar(TimeOut), sizeof(Waittime));
setsockopt(m_Socket, SOL_SOCKET, SO_REUSEADDR, nil, 0);
setsockopt(m_Socket, SOL_SOCKET, SO_KEEPALIVE, nil, 0);
Sleep(Wait);
FillChar(recvBuffer, recvlen, #0);
nReturn := recv(m_Socket, recvBuffer, recvlen, 0);
if nReturn <> SOCKET_ERROR then
begin
FillChar(sendBuffer, sendlen, #0);
StrCopy(sendBuffer, #255 + #252 + #35);
nReturn := send(m_Socket, sendBuffer, Strlen(sendBuffer), 0);
FillChar(sendBuffer, sendlen, #0);
StrCopy(sendBuffer, PChar(login.TelUsername + #13));
nReturn := send(m_Socket, sendBuffer, Strlen(sendBuffer), 0);
FillChar(recvBuffer, recvlen, #0);
nReturn := recv(m_Socket, recvBuffer, 1024, 0);
FillChar(sendBuffer, sendlen, #0);
StrCopy(sendBuffer, PChar(login.TelPassword + #13));
nReturn := send(m_Socket, sendBuffer, Strlen(sendBuffer), 0);
FillChar(recvBuffer, recvlen, #0);
Sleep(Wait);
nReturn := recv(m_Socket, recvBuffer, 1024, 0);
ShowMessage(recvBuffer);
end;
end;
WSACleanup();
end;