#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <string>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
int main (){
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
cout << "WSAStartup failed." << endl;
cin.get();
return 1;
}
string requestSend;
string sendHost = "feeds.feedburner.com";
string sendDirectory = "/failblog?format=xml";
requestSend += "GET ";
requestSend += sendDirectory;
requestSend +=" HTTP/1.1\r\n";
requestSend += "Host: ";
requestSend += sendHost;
requestSend += "\r\n";
requestSend += "Connection: close\r\n";
requestSend += "\r\n";
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
struct hostent *host;
host = gethostbyname(sendHost.c_str());
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(80);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
cout << "Connecting..." << endl;;
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) == SOCKET_ERROR ){ // or you could have !=0
cout << "Could not connect";
cin.get();
return 1;
}
cout << "Connected." << endl;
send(Socket,requestSend.c_str(), requestSend.length(),0);
char buffer[10000];
int dataLength = recv(Socket,(char*)&buffer,sizeof(buffer),0);
int i = 0;
char check1[] = {'c', 'h', 'e', 'e', 'z', 'b', 'u', 'r'}; //the string it searchers the end of the buffer for
//char check1[] = {'o', 'r', 'i', 'g', 'L', 'i', 'n', 'k'};
int checked;
while(i < dataLength)
{
checked = 1; // reset to 1 each time
cout << buffer[i];
for(int x = 0; x<=7; x++){
if(buffer[i-7+x] != check1[x]){
checked = 0;
break; //efficiency
}
}
if(checked){cout << "<---MATCH!";} //if the last 8 values of buffer are the same as the first 8 of check1
i ++;
}
cout << endl;
cout << "Size: " << i << endl;
cout << "datalength: " << dataLength << endl;
cout << "Size of buffer: " << sizeof(buffer) << endl;
cout << "Request length: " << requestSend.length() << endl;
closesocket(Socket);
WSACleanup();
cin.get();
return 0;
}Thanks in advance if anyone is able to help :crying:
Edited by reilly, 17 September 2010 - 08:37 PM.
added a few comments


Sign In
Create Account


Back to top









