Solved

Small web client

Posted on 2000-05-07
1
201 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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