|
-
December 5th, 2009, 04:19 PM
#1
winsock not recieving data
i wrote a simple socket client and for testing i tried to connect to a http server and send the http command 'GET / HTTP/1.1' but i get nothing back. i've looked through other post, and searched online, from everything i see it should work. here's the code:
Code:
target.sin_family = AF_INET;
target.sin_addr.s_addr = *((unsigned long *)host->h_addr);
sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (connect(sck, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
{
cout << "error connecting to target" << endl;
closesocket(sck);
WSACleanup();
return 0;
}
char outBuff[BUF_SIZE];
char inBuff[BUF_SIZE];
int bytes_recv;
do
{
cout << "->";
cin.getline(outBuff, BUF_SIZE-2);
if (strcmp(outBuff, "quit")==0) break;
strcat(outBuff, "\r\n");
if (send(sck, outBuff, strlen(outBuff), 0))
{
cout << "send successful" << endl;
bytes_recv = recv(sck, inBuff, BUF_SIZE, 0);
if (bytes_recv != 0 && bytes_recv != SOCKET_ERROR)
{
cout << inBuff << endl;
}
}
memset(outBuff, 0, BUF_SIZE);
memset(inBuff, 0, BUF_SIZE);
} while (true);
closesocket(sck);
WSACleanup();
-
December 5th, 2009, 06:47 PM
#2
Re: winsock not recieving data
Your HTTP statement is incomplete.
It should be something like:
Code:
char httpreq[] = "GET / HTTP/1.1\r\nHOST:website.com\r\n\r\n";
Notice the \r\ns
-
December 5th, 2009, 08:31 PM
#3
Re: winsock not recieving data
ahh it was an extra "\r\n" i needed. i knew it was something simple i was overlooking,
thank you that's been driving me crazy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|