rem Usage: rem ------ rem buildwin VS_VERSION [ACTION] [LINKMODE] [CONFIGURATION] [PLATFORM] [SAMPLES] [TESTS] [TOOL] rem VS_VERSION: 90|100|110|120|140|150 rem ACTION: build|rebuild|clean rem LINKMODE: static_mt|static_md|shared|all rem CONFIGURATION: release|debug|both rem PLATFORM: Win32|x64|WinCE|WEC2013 rem SAMPLES: samples|nosamples rem TESTS: tests|notests rem TOOL: devenv|vcexpress|wdexpress|msbuild
we choose to build with visual studio 2015
build_vs140.cmd
1 2
@echo off buildwin 140 build shared release x64 samples
build
1
./build_vs140.cmd
or
1
cmake-gui ..
cmake-gui and open sln to build with release x64and install to C:/Program Files/Poco so that find_package(Poco REQURIED) take effect.
1 2 3 4 5 6 7 8 9 10 11 12 13
$ ls Poco
bin include lib
$ ll Poco/lib
total 3.5M drwxr-xr-x 1 zunli zunli 0 Jan 25 07:39 cmake -rw-r--r-- 1 zunli zunli 1.5M Jan 25 06:59 PocoFoundation.lib -rw-r--r-- 1 zunli zunli 111K Jan 25 06:59 PocoJSON.lib -rw-r--r-- 1 zunli zunli 1007K Jan 25 07:00 PocoNet.lib -rw-r--r-- 1 zunli zunli 320K Jan 25 07:00 PocoUtil.lib -rw-r--r-- 1 zunli zunli 595K Jan 25 07:00 PocoXML.lib
# Always include the source and build directories in the include path. set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set the output folder where your program will be created set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
find_package(Poco REQUIRED COMPONENTS Foundation Util Net XML JSON)
# no Poco_INCLUDE_DIRS, we have to set by hand if(MSVC) # WIN32 SET(Poco_INCLUDE_DIRS "C:/Program Files/Poco/include") else() SET(Poco_INCLUDE_DIRS "/usr/local/include/Poco") endif(MSVC)
using Poco::Net::ServerSocket; using Poco::Net::HTTPRequestHandler; using Poco::Net::HTTPRequestHandlerFactory; using Poco::Net::HTTPServer; using Poco::Net::HTTPServerRequest; using Poco::Net::HTTPServerResponse; using Poco::Net::HTTPServerParams; using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::ThreadPool; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::OptionCallback; using Poco::Util::HelpFormatter;
voidhandleHelp(const std::string& name, const std::string& value) { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader( "A web server that serves the current date and time."); helpFormatter.format(std::cout); stopOptionsProcessing(); _helpRequested = true; }
using Poco::Net::ServerSocket; using Poco::Net::StreamSocket; using Poco::Net::TCPServerConnection; using Poco::Net::TCPServerConnectionFactory; using Poco::Net::TCPServer; using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::HelpFormatter;
classTimeServerConnection : public TCPServerConnection /// This class handles all client connections. /// /// A string with the current date and time is sent back to the client. { public: TimeServerConnection(const StreamSocket& s, const std::string& format) : TCPServerConnection(s), _format(format) { }
classTimeServer : public Poco::Util::ServerApplication /// The main application class. /// /// This class handles command-line arguments and /// configuration files. /// Start the TimeServer executable with the help /// option (/help on Windows, --help on Unix) for /// the available command line options. /// /// To use the sample configuration file (TimeServer.properties), /// copy the file to the directory where the TimeServer executable /// resides. If you start the debug version of the TimeServer /// (TimeServerd[.exe]), you must also create a copy of the configuration /// file named TimeServerd.properties. In the configuration file, you /// can specify the port on which the server is listening (default /// 9911) and the format of the date/time string sent back to the client. /// /// To test the TimeServer you can use any telnet client (telnet localhost 9911). { public: TimeServer() : _helpRequested(false) { }
voiddisplayHelp() { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader("A server application that serves the current date and time."); helpFormatter.format(std::cout); }
intmain(const std::vector<std::string>& args) { if (_helpRequested) { displayHelp(); } else { // get parameters from configuration file unsignedshort port = (unsignedshort)config().getInt("TimeServer.port", 9911); std::string format(config().getString("TimeServer.format", DateTimeFormat::ISO8601_FORMAT));
// set-up a server socket ServerSocket svs(port); // set-up a TCPServer instance TCPServer srv(new TimeServerConnectionFactory(format), svs); // start the TCPServer srv.start(); // wait for CTRL-C or kill waitForTerminationRequest(); // Stop the TCPServer srv.stop(); } return Application::EXIT_OK; }