Click here to Skip to main content
12,510,403 members (51,771 online)
Click here to Skip to main content

Stats

273.6K views
6.9K downloads
203 bookmarked
Posted

A C++ Embedded Web Server

, 23 Jun 2014 BSD
Give a C++ application its own web page
code_project
examples
webemCalendar
calendar.dat
sqlite3.dll
webemCalendar.vcproj.CORVIS.james.user
webemHello
webemHello.vcproj.CORVIS.james.user
webemHelloForm
webemHelloForm.vcproj.CORVIS.james.user
webemMT
webemMT.vcproj.CORVIS.james.user
src
sqlite
sqlite3.lib
webem
server
Jamfile
Jamfile.v2
manifest
manifest.uuid
webem.fossil
_FOSSIL_
doc
DoxyFile
html
doxygen.png
tab_b.gif
tab_l.gif
tab_r.gif
examples
webemButton
webemCalendar
calendar.dat
sqlite3.dll
sqlite3.lib
WebemHello
webemHelloForm
server
// webemMT.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/thread.hpp>

#include "../src/Webem/cWebem.h"

class cLive
{
	int count;
public:
	cLive() : count(0) {}
	void Increment()
	{
		count++;
		printf("I am still alive at %d\n",count);
	}
	void Block()
	{
		while ( 1 ) {
			Increment();
			Sleep(3000);
		}
	}
	char * DisplayHTML()
	{
		static char buf[1000];
		sprintf(buf,
			"cLive::Increment() has been called %d times\n",
			count );
		return buf;
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	cLive live;

	// Initialise web server.

	// The server listens on port entered on command line, default 1570

	char * port = "1570";	// default port
	if( argc == 2 )
		port = argv[1];		// port on command line
    http::server::cWebem theServer("0.0.0.0", port, ".\\");


	// Whenever server sees <!--#webem count -->
	// call cTable::Display() and include the HTML returned
	theServer.RegisterIncludeCode( "count", 
		boost::bind( 
		&cLive::DisplayHTML,	// member function
		&live ) );			// instance of class

	boost::thread* pThread = new boost::thread(
		boost::bind( 
		&http::server::cWebem::Run,	// member function
		&theServer ) );			// instance of class

	live.Block();
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

ravenspoint
Founder Raven's Point Consulting
Canada Canada
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 23 Jun 2014
Article Copyright 2008 by ravenspoint
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid