forked from bitshares/websocketpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/0.3.x-cmake' into cmake_prebui…
…ld_system Conflicts: websocketpp/endpoint.hpp
- Loading branch information
Showing
78 changed files
with
3,475 additions
and
966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,3 +75,5 @@ build/ | |
examples/wsperf/wsperf_client | ||
|
||
*.out | ||
|
||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## iostream server 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('iostream_server', ["iostream_server.cpp"], LIBS = ALL_LIBS) | ||
else: | ||
ALL_LIBS = boostlibs(['system','regex'],env) + [platform_libs] + [polyfill_libs] | ||
prgs += env.Program('iostream_server', ["iostream_server.cpp"], LIBS = ALL_LIBS) | ||
|
||
Return('prgs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <websocketpp/config/core.hpp> | ||
|
||
#include <websocketpp/server.hpp> | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
|
||
typedef websocketpp::server<websocketpp::config::core> 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) { | ||
if (msg->get_opcode() == websocketpp::frame::opcode::text) { | ||
s->get_alog().write(websocketpp::log::alevel::app, | ||
"Text Message Received: "+msg->get_payload()); | ||
} else { | ||
s->get_alog().write(websocketpp::log::alevel::app, | ||
"Binary Message Received: "+websocketpp::utility::to_hex(msg->get_payload())); | ||
} | ||
|
||
try { | ||
s->send(hdl, msg->get_payload(), msg->get_opcode()); | ||
} catch (const websocketpp::lib::error_code& e) { | ||
s->get_alog().write(websocketpp::log::alevel::app, | ||
"Echo Failed: "+e.message()); | ||
} | ||
} | ||
|
||
int main() { | ||
server s; | ||
std::ofstream log; | ||
|
||
try { | ||
// set up access channels to only log interesting things | ||
s.clear_access_channels(websocketpp::log::alevel::all); | ||
s.set_access_channels(websocketpp::log::alevel::connect); | ||
s.set_access_channels(websocketpp::log::alevel::disconnect); | ||
s.set_access_channels(websocketpp::log::alevel::app); | ||
|
||
// Log to a file rather than stdout, as we are using stdout for real | ||
// output | ||
log.open("output.log"); | ||
s.get_alog().set_ostream(&log); | ||
s.get_elog().set_ostream(&log); | ||
|
||
// print all output to stdout | ||
s.register_ostream(&std::cout); | ||
|
||
// Register our message handler | ||
s.set_message_handler(bind(&on_message,&s,::_1,::_2)); | ||
|
||
server::connection_ptr con = s.get_connection(); | ||
|
||
con->start(); | ||
|
||
// C++ iostream's don't support the idea of asynchronous i/o. As such | ||
// there are two input strategies demonstrated here. Buffered I/O will | ||
// read from stdin in chunks until EOF. This works very well for | ||
// replaying canned connections as would be done in automated testing. | ||
// | ||
// If the server is being used live however, assuming input is being | ||
// piped from elsewhere in realtime, this strategy will result in small | ||
// messages being buffered forever. The non-buffered strategy below | ||
// reads characters from stdin one at a time. This is inefficient and | ||
// for more serious uses should be replaced with a platform specific | ||
// asyncronous i/o technique like select, poll, IOCP, etc | ||
bool buffered_io = false; | ||
|
||
if (buffered_io) { | ||
std::cin >> *con; | ||
} else { | ||
char a; | ||
while(std::cin.get(a)) { | ||
con->readsome(&a,1); | ||
} | ||
} | ||
} 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; | ||
} | ||
log.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Print server 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('print_server', ["print_server.cpp"], LIBS = ALL_LIBS) | ||
else: | ||
ALL_LIBS = boostlibs(['system','regex'],env) + [platform_libs] + [polyfill_libs] | ||
prgs += env.Program('print_server', ["print_server.cpp"], LIBS = ALL_LIBS) | ||
|
||
Return('prgs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
|
||
#include <websocketpp/config/asio_no_tls.hpp> | ||
#include <websocketpp/server.hpp> | ||
|
||
typedef websocketpp::server<websocketpp::config::asio> server; | ||
|
||
void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg) { | ||
std::cout << msg->get_payload() << std::endl; | ||
} | ||
|
||
int main() { | ||
server print_server; | ||
|
||
print_server.set_message_handler(&on_message); | ||
|
||
print_server.init_asio(); | ||
print_server.listen(9002); | ||
print_server.start_accept(); | ||
|
||
print_server.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('subprotocol_server', ["subprotocol_server.cpp"], LIBS = ALL_LIBS) | ||
else: | ||
ALL_LIBS = boostlibs(['system','regex'],env) + [platform_libs] + [polyfill_libs] | ||
prgs += env.Program('subprotocol_server', ["subprotocol_server.cpp"], LIBS = ALL_LIBS) | ||
|
||
Return('prgs') |
Oops, something went wrong.