Solved

Small web client

Posted on 2000-05-07
1
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 153
is twain_32.dll cmpatible with windows 10 ? 10 233
Exception thrown at 0x00007FFD5BC81F28 7 55
How can i compile this github project?? 2 99
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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 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