diff --git a/SConstruct b/SConstruct index 6ffe789464..8081771747 100644 --- a/SConstruct +++ b/SConstruct @@ -59,6 +59,7 @@ if env['PLATFORM'].startswith('win'): 'WIN32_LEAN_AND_MEAN', '_WIN32_WINNT=0x0600', '_CONSOLE', + 'BOOST_TEST_DYN_LINK', 'NOMINMAX', '_WEBSOCKETPP_CPP11_FRIEND_', '_WEBSOCKETPP_CPP11_MEMORY_', @@ -192,6 +193,9 @@ if not env['PLATFORM'].startswith('win'): # Main test application #main = SConscript('#/examples/dev/SConscript',variant_dir = builddir + 'dev',duplicate = 0) +# testee_server +testee_server = SConscript('#/examples/testee_server/SConscript',variant_dir = builddir + 'testee_server',duplicate = 0) + # echo_server echo_server = SConscript('#/examples/echo_server/SConscript',variant_dir = builddir + 'echo_server',duplicate = 0) diff --git a/examples/testee_server/SConscript b/examples/testee_server/SConscript new file mode 100644 index 0000000000..da4fff5cca --- /dev/null +++ b/examples/testee_server/SConscript @@ -0,0 +1,23 @@ +## Main development example +## + +Import('env') +Import('env_cpp11') +Import('boostlibs') +Import('platform_libs') +Import('polyfill_libs') + +env = env.Clone () +env_cpp11 = env_cpp11.Clone () + +prgs = [] + +# if a C++11 environment is avaliable build using that, otherwise use boost +if env_cpp11.has_key('WSPP_CPP11_ENABLED'): + ALL_LIBS = boostlibs(['system'],env_cpp11) + [platform_libs] + [polyfill_libs] + prgs += env_cpp11.Program('testee_server', ["testee_server.cpp"], LIBS = ALL_LIBS) +else: + ALL_LIBS = boostlibs(['system','regex'],env) + [platform_libs] + [polyfill_libs] + prgs += env.Program('testee_server', ["testee_server.cpp"], LIBS = ALL_LIBS) + +Return('prgs') diff --git a/examples/testee_server/testee_server.cpp b/examples/testee_server/testee_server.cpp new file mode 100644 index 0000000000..46b83b4453 --- /dev/null +++ b/examples/testee_server/testee_server.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013, Peter Thorson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the WebSocket++ Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include + +typedef websocketpp::server server; + +using websocketpp::lib::placeholders::_1; +using websocketpp::lib::placeholders::_2; +using websocketpp::lib::bind; + +// pull out the type of messages sent by our config +typedef server::message_ptr message_ptr; + +// Define a callback to handle incoming messages +void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { + s->send(hdl, msg->get_payload(), msg->get_opcode()); +} + +int main() { + // Create a server endpoint + server testee_server; + + try { + // Set logging settings + testee_server.set_access_channels(websocketpp::log::alevel::none); + testee_server.clear_access_channels(websocketpp::log::alevel::none); + + // Initialize ASIO + testee_server.init_asio(); + + // Register our message handler + testee_server.set_message_handler(bind(&on_message,&testee_server,::_1,::_2)); + + // Listen on port 9002 + testee_server.listen(9002); + + // Start the server accept loop + testee_server.start_accept(); + + // Start the ASIO io_service run loop + testee_server.run(); + } catch (const std::exception & e) { + std::cout << e.what() << std::endl; + } catch (websocketpp::lib::error_code e) { + std::cout << e.message() << std::endl; + } catch (...) { + std::cout << "other exception" << std::endl; + } +}