What do you mean the program will connect through telnet? Is there a telnet server or is the actual program you want written the server, and YOU connect to it through telnet?
EDIT: Heres some code i've written for you. I have not tested it (you havnt provided the server program for me to test it with) but it compiles without any warnings/errors. You need to link the wsock32 lib
Code:
#include <stdio.h>
#include <string.h>
#include <winsock2.h>
#include <windows.h>
const char SERVER_IP[] = "127.0.0.1";
const unsigned short SERVER_PORT = 8674;
size_t RecvLine(unsigned int socketId, char* out, size_t outSize);
int main (int argc, char *argv[])
{
char msgBuffer[0xFFFF];
//Initialize Winsock (version 2.2)
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2),&wsaData);
//Create a TCP socket
unsigned int socketId = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(socketId)
{
//Fill in server IP and PORT into address header
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(SERVER_IP);
addr.sin_port = htons(SERVER_PORT);
//Try and connect to the server
if(connect(socketId, (SOCKADDR*)&addr, sizeof(addr)) != -1)
{
//If we succesfully connected, than send the "AUTH 1287" message
strncpy(msgBuffer, "AUTH 1287\n", sizeof(msgBuffer));
send(socketId, msgBuffer, strlen(msgBuffer), 0);
//Receive the next line
if(RecvLine(socketId, msgBuffer, sizeof(msgBuffer)))
{
//Check if the line we received is "Correct! 250"
if(strcmp(msgBuffer, "Correct! 250") == 0)
{
while(1)
{
//Send the "Show stats" line
strncpy(msgBuffer, "Show stats\n", sizeof(msgBuffer));
send(socketId, msgBuffer, strlen(msgBuffer), 0);
Sleep(60000); //Wait 60 secs
}
} else printf("Error. Incorrect response from server\n");
}
}
}
//Free winsock
WSACleanup();
return 1;
}
//Receives a line from a socket
size_t RecvLine(unsigned int socketId, char* out, size_t outSize)
{
char byte;
size_t recvCount = 0;
//Clear the out buffer
memset(out, 0, outSize);
for(; recvCount < outSize - 1; ++recvCount)
{
if(recv(socketId, &byte, 1, 0) > 0)
{
if(byte != '\n')
out[recvCount] = byte;
else break;
} else break;
}
//Trim the line (any \r, \n,etc)
while(recvCount)
{
if(out[recvCount-1] < ' ')
out[--recvCount] = 0;
else break;
}
return recvCount;
}
As you can see it's alot more complex than what you would do in VB and you should have a decent amount of c/c++ knowledge before you go into sockets.