|
// 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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.