66#include " hub_connection.h"
77#include " log_writer.h"
88#include < future>
9+ #include " signalr_value.h"
910
1011class logger : public signalr ::log_writer
1112{
1213 // Inherited via log_writer
1314 virtual void __cdecl write (const std::string & entry) override
1415 {
15- // std::cout << utility::conversions::to_utf8string( entry) << std::endl;
16+ std::cout << entry << std::endl;
1617 }
1718};
1819
1920void send_message (signalr::hub_connection& connection, const std::string& message)
2021{
21- web::json ::value args{ };
22- args[ 0 ] = web::json:: value( utility::conversions::to_string_t (message) );
22+ std::vector<signalr ::value> arr { std::string ( " c++ " ), message };
23+ signalr:: value args (arr );
2324
2425 // if you get an internal compiler error uncomment the lambda below or install VS Update 4
25- connection.invoke (" Send" , args, [](const web::json ::value& value, std::exception_ptr exception)
26+ connection.invoke (" Send" , args, [](const signalr ::value& value, std::exception_ptr exception)
2627 {
2728 try
2829 {
@@ -31,21 +32,28 @@ void send_message(signalr::hub_connection& connection, const std::string& messag
3132 std::rethrow_exception (exception);
3233 }
3334
34- ucout << U (" Received: " ) << value.serialize () << std::endl;
35+ if (value.is_string ())
36+ {
37+ std::cout << " Received: " << value.as_string () << std::endl;
38+ }
39+ else
40+ {
41+ std::cout << " hub method invocation has completed" << std::endl;
42+ }
3543 }
3644 catch (const std::exception &e)
3745 {
38- ucout << U ( " Error while sending data: " ) << e.what () << std::endl;
46+ std::cout << " Error while sending data: " << e.what () << std::endl;
3947 }
4048 });
4149}
4250
4351void chat ()
4452{
4553 signalr::hub_connection connection (" http://localhost:5000/default" , signalr::trace_level::all, std::make_shared<logger>());
46- connection.on (" Send" , [](const web::json ::value & m)
54+ connection.on (" Send" , [](const signalr ::value & m)
4755 {
48- ucout << std::endl << m.at ( 0 ) .as_string () << /* U(" wrote:") << m.at(1).as_string() << */ std::endl << U ( " Enter your message: " ) ;
56+ std::cout << std::endl << m.as_array ()[ 0 ] .as_string () << std::endl << " Enter your message: " ;
4957 });
5058
5159 std::promise<void > task;
@@ -59,13 +67,13 @@ void chat()
5967 }
6068 catch (const std::exception & ex)
6169 {
62- ucout << U ( " exception when starting connection: " ) << ex.what () << std::endl;
70+ std::cout << " exception when starting connection: " << ex.what () << std::endl;
6371 }
6472 task.set_value ();
6573 return ;
6674 }
6775
68- ucout << U ( " Enter your message:" ) ;
76+ std::cout << " Enter your message:" ;
6977 for (;;)
7078 {
7179 std::string message;
@@ -88,11 +96,11 @@ void chat()
8896 std::rethrow_exception (exception);
8997 }
9098
91- ucout << U ( " connection stopped successfully" ) << std::endl;
99+ std::cout << " connection stopped successfully" << std::endl;
92100 }
93101 catch (const std::exception & e)
94102 {
95- ucout << U ( " exception when stopping connection: " ) << e.what () << std::endl;
103+ std::cout << " exception when stopping connection: " << e.what () << std::endl;
96104 }
97105
98106 task.set_value ();
0 commit comments