Solved

Small web client

Posted on 2000-05-07
1
202 Views
Last Modified: 2010-04-02
Hello,
I need to build as small as possible client that will connect to some URL and will parse short response from it.
What will be the best way to do it?
(I don't want to use MFC).

Thanks for any suggestion,
arnon@zzn.com
0
Comment
Question by:arnonayal
1 Comment
 
LVL 2

Accepted Solution

by:
arikka earned 150 total points
ID: 2785881
// This is simple WEB client without MFC
// It uses WinSock ( add wsock32.lib in project settings)


#include <windows.h>
#include <winsock.h>
#include <stdio.h>

void TRACE(char *str)
{
   FILE *fp=fopen("browser.log","a+");
   fprintf(fp,"%s\n",str);
   fclose(fp);
}

/////////////////////////////////////////////////////////////

WNDCLASS wndCls;
HWND hWnd;
MSG msg;

long _stdcall wndProc (HWND,UINT,WPARAM,LPARAM);

int _stdcall WinMain(HINSTANCE inst,HINSTANCE j,char *cmdLine,int l)
{
        wndCls.lpszClassName ="something";
        wndCls.hInstance = inst;
        wndCls.lpfnWndProc = wndProc;

        wndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

        RegisterClass(&wndCls);
        hWnd = CreateWindow("something","WEB Client",
                                 WS_OVERLAPPEDWINDOW,
                                           CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             NULL,
                             NULL,
                             inst,
                             NULL);

        ShowWindow(hWnd,3);
      UpdateWindow(hWnd);


        while (GetMessage(&msg,0,0,0) )
               DispatchMessage(&msg);

        return 1;
}
/////////////////////////////////////////////////////////////

WSADATA wsdata;
SOCKET s;
sockaddr_in sa;
struct hostent *host;

int d;

char buf   [200];
char buf_2 [1000];

long _stdcall wndProc (HWND hwind,UINT message, WPARAM wParam,LPARAM lParam)
{

        if ( message == WM_LBUTTONDOWN)
        {

          d = WSAStartup(0x0101,&wsdata);
          s = socket(AF_INET,SOCK_STREAM,0);
          sa.sin_family = AF_INET;
          sa.sin_port = htons(80);

        host = gethostbyname("WEB SERVER NAME HERE");
        sa.sin_addr.s_addr=*((unsigned long *) host->h_addr);

          d = connect(s,(struct sockaddr *)&sa,sizeof(sa));
// here insert your URL
          strcpy(buf,"GET aaa/bbb/ccc/html.htm \r\n");
          d = send(s, buf, strlen(buf),0);
          d = 1;
          while(d !=0)
        {
                strset(buf_2,' ');
                d = recv(s,buf_2, sizeof(buf_2),0);
                TRACE(buf_2);
        }
          MessageBox(0,"All","Over",0);

        }

        if ( message == WM_DESTROY)
            PostQuitMessage(0);

        return DefWindowProc(hwind, message, wParam,lParam);
}

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question