![]() |
| | #1 |
| Registered User Join Date: Mar 2006
Posts: 143
| http requests Code: SOCKET call_socket (const char *hostname, unsigned short portnum)
{
struct sockaddr_in sa;
struct hostent *hp;
SOCKET s;
hp = gethostbyname (hostname);
if (hp == NULL)
return INVALID_SOCKET;
memset (&sa, 0, sizeof (sa));
memcpy ((char *) &sa.sin_addr, hp->h_addr, hp->h_length);
sa.sin_family = hp->h_addrtype;
sa.sin_port = htons ((u_short) portnum);
s = socket (hp->h_addrtype, SOCK_STREAM, 0);
if (s == INVALID_SOCKET)
{
closesocket(s);
return INVALID_SOCKET;
}
if (connect (s, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)) == SOCKET_ERROR)
{
closesocket(s);
cout << WSAGetLastError();
return INVALID_SOCKET;
}
return s;
}
int main ()
{
WSADATA wsaDat;
SOCKET test;
if (WSAStartup (MAKELONG (1, 1), &wsaDat) == SOCKET_ERROR)
{
cout << "Problem!!!";
return -1;
}
if (call_socket ("webpages.atlanticbb.net", 50000) == INVALID_SOCKET)
{
cout << "That failed!!!";
system ("pause");
return -1;
}
return 0;
}
|
| xixpsychoxix is offline | |
| | #2 | |
| CSharpener Join Date: Oct 2006
Posts: 5,323
| Quote:
What function has failed and what error code you get?
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |
| vart is offline | |
| | #3 |
| Malum in se Join Date: Apr 2007
Posts: 3,188
| If you are using windows, dont use teh winsock functions, use HttpSendRequest() and its ilk.
__________________ Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off. |
| abachler is offline | |
| | #4 |
| Registered User Join Date: Mar 2005 Location: Juneda
Posts: 229
| "... for some reason i cannot connect..." Maybe because by default web servers are not listening on port 50000? ![]() Code: call_socket ("webpages.atlanticbb.net",80)
|
| Niara is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Persistent HTTP Requests | reelbigtim | Networking/Device Communication | 9 | 10-08-2008 12:06 AM |
| Timing HTTP GET requests | traef06 | C Programming | 9 | 09-08-2008 09:33 PM |
| viewing HTTP requests | DavidP | General Discussions | 6 | 04-09-2007 06:44 PM |
| Writing all HTTP requests from a website to a log file | goomyman | C# Programming | 1 | 07-29-2005 09:18 AM |