HomeProjectsServicesContactus
» Guest
  Sign In     Register    
Projects » HTTP Web Server
Developer : Ritey
Date : 2005-03-27 00:00

» Summary :

C++ class to add a basic web server to your application.

» Catagories :


  • Development Status: Stable
  • Operating System: Windows
  • Development Environment: MSVC.NET

» Latest Project Downloads:

Total Download Count For Project : 546
 
CWebServerCWebServer.zip
 2006-04-17Source Code9 KbNotes / ChangesMD5:bced3d38e6d693d5004dad09f792dd86458 HitsDownload
 

» Project Information :

Class CWebServer
This class is a small scale http web server capable of handling GET and POST requests.

When a request has been received an application defined callback is called with the request info, so that the user can provide the content in the response.

Various response status functions have been added to make life easier. Such as SendNotAuthorized() which will send the not authorized response to the client, thus making them log on using basic authentication.

A couple of my projects that use this class can be found here:-
Netgear SysLog
MusicService


CWebServer Methods:

::InitWinsock()
Calls WSAStartUp().

::CleanupWinsock()
Calls WSACleanup().

::Start()
Starts the web server.

::Stop()
Stops the web server.

::GetConnectionCount()
Returns the number of current client connections.


Class CWebHandler
This class is used to handle the accepted connection. The request is received and parsed here. And this class is used to send the response to the client.

You dont need to create one of these classes because they are created by CWebServer and passed to the program via the callback. From where you can access the methods/properties.

<hr>CWebHandler Methods

::SendResponse()
Send content to the client.

::SendNotModified()
::SendNotAuthorized()
::SendNotFound()
::SendForbidden()
::SendServerError()
::SendBadMethod()

These functions send miscellanious status responses to the client.

CWebHandler Properties

::m_req
Contains information about the http client request, such as common headers post data etc.

::m_sa
Is the sockadd_in of the client.


<hr>Sample Usage:
Code:
#include "WebServer.h"
#include <stdio.h>
#include <conio.h>

//
// Request Handler
//
BOOL RequestHandler(CWebHandler *pHandler) {

char *lpzContent = "<b>This is the content!</b>";

return pHandler->SendResponse(CONTENT_HTML,lpzContent,-1,0,0);
}


//
// Program Entry Point
//
void main( void ) {

CWebServer svr;

//Init winsock
if (!svr.InitWinsock()) return;

//start the server
if (!svr.Start(80,RequestHandler,50,0)) goto fin;

//press any key to stop the server
while (_kbhit()) Sleep(1);
getch();

//stop the server
svr.Stop();

fin:
svr.CleanupWinsock();
}

0 member(s), 13 guest(s)
| Site Map | Statistics | Terms of Use | Privacy Policy |
Copyright (C) GoCoding.Com 2004-2007
Powered by Seditio
Contacts