Solved

Small web client

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now