#include "stdafx.h" const char * hostname = "coldcut"; const int port = 5050; const char * req = "GET / HTTP/1.0\r\n\r\n"; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WSADATA wsaData ; if (WSAStartup(0x101, &wsaData) == SOCKET_ERROR) { MessageBox(NULL, L"Unable to start winsock", L"", MB_OK); return -1; } sockaddr_in addr = {0}; addr.sin_port = htons(port); addr.sin_family = AF_INET; struct hostent * ph = 0 ; ph = gethostbyname(hostname) ; if ( !ph ) { MessageBox(NULL, L"Unable to resolve hostname", L"", MB_OK); return -2; } memcpy(&addr.sin_addr, ph->h_addr, ph->h_length ); SOCKET s = socket(AF_INET, SOCK_STREAM, 0); if ( connect(s, (struct sockaddr*)&addr, sizeof(addr) ) == SOCKET_ERROR) { MessageBox(NULL, L"Unable to connect", L"", MB_OK); return -3; } int rc = send(s, req, strlen(req), 0); if (rc == SOCKET_ERROR ) { MessageBox(NULL, L"Unable to send data", L"", MB_OK); return -4; } char * buff = new char[8192]; int cb = recv(s, buff, 8191, 0); if (cb == SOCKET_ERROR) { delete buff; MessageBox(NULL, L"Unable to read data", L"", MB_OK); return -5; } closesocket(s); buff[cb] = 0; WCHAR * wbuff = new WCHAR[8192]; wsprintf(wbuff, L"%S", buff); MessageBox(NULL, wbuff, L"", MB_OK); delete buff; WSACleanup(); return 0; }