forked from steemit/fc
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from bitshares/jmj_844b
Log host information from websocket requests
- Loading branch information
Showing
8 changed files
with
314 additions
and
117 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,41 @@ | ||
#include <fc/network/http/websocket.hpp> | ||
#include <websocketpp/error.hpp> | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <fc/log/logger.hpp> | ||
#include <fc/log/console_appender.hpp> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
try | ||
{ | ||
// set up logging | ||
fc::appender::ptr ca(new fc::console_appender); | ||
fc::logger l = fc::logger::get("rpc"); | ||
l.add_appender( ca ); | ||
|
||
fc::http::websocket_client client; | ||
fc::http::websocket_connection_ptr s_conn, c_conn; | ||
std::string url = argv[1]; | ||
wlog( "Connecting to server at url ${url}", ("url", url) ); | ||
c_conn = client.connect( "ws://" + url ); | ||
|
||
std::string echo; | ||
c_conn->on_message_handler([&](const std::string& s){ | ||
echo = s; | ||
}); | ||
c_conn->send_message( "hello world" ); | ||
fc::usleep( fc::milliseconds(500) ); | ||
if (echo != std::string("echo: hello world") ) | ||
wlog( "Test1 failed, echo value: [${echo}]", ("echo", echo) ); | ||
c_conn->send_message( "again" ); | ||
fc::usleep( fc::milliseconds(500) ); | ||
if ("echo: again" != echo) | ||
wlog( "Test2 failed, echo value: [${echo}]", ("echo", echo) ); | ||
} | ||
catch (const websocketpp::exception& ex) | ||
{ | ||
elog( "websocketpp::exception thrown: ${err}", ("err", ex.what()) ); | ||
} | ||
} |
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,33 @@ | ||
#include <fc/network/http/websocket.hpp> | ||
#include <fc/asio.hpp> | ||
|
||
#include <iostream> | ||
#include <chrono> | ||
#include <fc/log/logger.hpp> | ||
#include <fc/log/console_appender.hpp> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
// set up logging | ||
fc::appender::ptr ca(new fc::console_appender); | ||
fc::logger l = fc::logger::get("rpc"); | ||
l.add_appender( ca ); | ||
|
||
fc::http::websocket_server server("MyForwardHeaderKey"); | ||
|
||
server.on_connection([&]( const fc::http::websocket_connection_ptr& c ){ | ||
c->on_message_handler([&](const std::string& s){ | ||
c->send_message("echo: " + s); | ||
}); | ||
}); | ||
|
||
server.listen( 0 ); | ||
server.start_accept(); | ||
|
||
wlog( "Port: ${port}", ("port", server.get_listening_port()) ); | ||
|
||
while( true ) | ||
{ | ||
fc::usleep( fc::microseconds(100) ); | ||
} | ||
} |