Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocket_endpoint Class Reference

Public Member Functions

 websocket_endpoint ()
 
 ~websocket_endpoint ()
 
int connect (std::string const &uri)
 
void close (int id, websocketpp::close::status::value code, std::string reason)
 
connection_metadata::ptr get_metadata (int id) const
 
 websocket_endpoint ()
 
 ~websocket_endpoint ()
 
int connect (std::string const &uri)
 
void close (int id, websocketpp::close::status::value code, std::string reason)
 
void send (int id, std::string message)
 
connection_metadata::ptr get_metadata (int id) const
 
 websocket_endpoint ()
 
 websocket_endpoint ()
 
int connect (std::string const &uri)
 
connection_metadata::ptr get_metadata (int id) const
 
 websocket_endpoint ()
 
 ~websocket_endpoint ()
 
int connect (std::string const &uri)
 
void close (int id, websocketpp::close::status::value code, std::string reason)
 
connection_metadata::ptr get_metadata (int id) const
 
 websocket_endpoint ()
 
 ~websocket_endpoint ()
 
int connect (std::string const &uri)
 
void close (int id, websocketpp::close::status::value code, std::string reason)
 
void send (int id, std::string message)
 
connection_metadata::ptr get_metadata (int id) const
 

Detailed Description

Definition at line 113 of file scratch_client.cpp.

Constructor & Destructor Documentation

◆ websocket_endpoint() [1/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 115 of file scratch_client.cpp.

115 : m_next_id(0) {
118
119 m_endpoint.init_asio();
120 m_endpoint.start_perpetual();
121
122 m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
123 }
void clear_access_channels(log::level channels)
Clear Access logging channels.
Definition endpoint.hpp:231
void clear_error_channels(log::level channels)
Clear Error logging channels.
Definition endpoint.hpp:253
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
Here is the call graph for this function:

◆ ~websocket_endpoint() [1/4]

websocket_endpoint::~websocket_endpoint ( )
inline

Definition at line 125 of file scratch_client.cpp.

125 {
126 m_endpoint.stop_perpetual();
127
128 for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
129 if (it->second->get_status() != "Open") {
130 // Only close open connections
131 continue;
132 }
133
134 std::cout << "> Closing connection " << it->second->get_id() << std::endl;
135
136 websocketpp::lib::error_code ec;
137 m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
138 if (ec) {
139 std::cout << "> Error closing connection " << it->second->get_id() << ": "
140 << ec.message() << std::endl;
141 }
142 }
143
144 m_thread->join();
145 }
void close(connection_hdl hdl, close::status::value const code, std::string const &reason, lib::error_code &ec)
Here is the call graph for this function:

◆ websocket_endpoint() [2/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 134 of file utility_client.cpp.

134 : m_next_id(0) {
137
138 m_endpoint.init_asio();
139 m_endpoint.start_perpetual();
140
141 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
142 }
Here is the call graph for this function:

◆ ~websocket_endpoint() [2/4]

websocket_endpoint::~websocket_endpoint ( )
inline

Definition at line 144 of file utility_client.cpp.

144 {
145 m_endpoint.stop_perpetual();
146
147 for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
148 if (it->second->get_status() != "Open") {
149 // Only close open connections
150 continue;
151 }
152
153 std::cout << "> Closing connection " << it->second->get_id() << std::endl;
154
155 websocketpp::lib::error_code ec;
156 m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
157 if (ec) {
158 std::cout << "> Error closing connection " << it->second->get_id() << ": "
159 << ec.message() << std::endl;
160 }
161 }
162
163 m_thread->join();
164 }
Here is the call graph for this function:

◆ websocket_endpoint() [3/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 44 of file step3.cpp.

44 {
47
48 m_endpoint.init_asio();
49 m_endpoint.start_perpetual();
50
51 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
52 }
Here is the call graph for this function:

◆ websocket_endpoint() [4/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 93 of file step4.cpp.

93 : m_next_id(0) {
96
97 m_endpoint.init_asio();
98 m_endpoint.start_perpetual();
99
100 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
101 }
Here is the call graph for this function:

◆ websocket_endpoint() [5/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 115 of file step5.cpp.

115 : m_next_id(0) {
118
119 m_endpoint.init_asio();
120 m_endpoint.start_perpetual();
121
122 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
123 }
Here is the call graph for this function:

◆ ~websocket_endpoint() [3/4]

websocket_endpoint::~websocket_endpoint ( )
inline

Definition at line 125 of file step5.cpp.

125 {
126 m_endpoint.stop_perpetual();
127
128 for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
129 if (it->second->get_status() != "Open") {
130 // Only close open connections
131 continue;
132 }
133
134 std::cout << "> Closing connection " << it->second->get_id() << std::endl;
135
136 websocketpp::lib::error_code ec;
137 m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
138 if (ec) {
139 std::cout << "> Error closing connection " << it->second->get_id() << ": "
140 << ec.message() << std::endl;
141 }
142 }
143
144 m_thread->join();
145 }
Here is the call graph for this function:

◆ websocket_endpoint() [6/6]

websocket_endpoint::websocket_endpoint ( )
inline

Definition at line 134 of file step6.cpp.

134 : m_next_id(0) {
137
138 m_endpoint.init_asio();
139 m_endpoint.start_perpetual();
140
141 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&client::run, &m_endpoint);
142 }
Here is the call graph for this function:

◆ ~websocket_endpoint() [4/4]

websocket_endpoint::~websocket_endpoint ( )
inline

Definition at line 144 of file step6.cpp.

144 {
145 m_endpoint.stop_perpetual();
146
147 for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
148 if (it->second->get_status() != "Open") {
149 // Only close open connections
150 continue;
151 }
152
153 std::cout << "> Closing connection " << it->second->get_id() << std::endl;
154
155 websocketpp::lib::error_code ec;
156 m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
157 if (ec) {
158 std::cout << "> Error closing connection " << it->second->get_id() << ": "
159 << ec.message() << std::endl;
160 }
161 }
162
163 m_thread->join();
164 }
Here is the call graph for this function:

Member Function Documentation

◆ close() [1/4]

void websocket_endpoint::close ( int id,
websocketpp::close::status::value code,
std::string reason )
inline

Definition at line 185 of file scratch_client.cpp.

185 {
186 websocketpp::lib::error_code ec;
187
188 con_list::iterator metadata_it = m_connection_list.find(id);
189 if (metadata_it == m_connection_list.end()) {
190 std::cout << "> No connection found with id " << id << std::endl;
191 return;
192 }
193
194 m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
195 if (ec) {
196 std::cout << "> Error initiating close: " << ec.message() << std::endl;
197 }
198 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close() [2/4]

void websocket_endpoint::close ( int id,
websocketpp::close::status::value code,
std::string reason )
inline

Definition at line 210 of file utility_client.cpp.

210 {
211 websocketpp::lib::error_code ec;
212
213 con_list::iterator metadata_it = m_connection_list.find(id);
214 if (metadata_it == m_connection_list.end()) {
215 std::cout << "> No connection found with id " << id << std::endl;
216 return;
217 }
218
219 m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
220 if (ec) {
221 std::cout << "> Error initiating close: " << ec.message() << std::endl;
222 }
223 }
Here is the call graph for this function:

◆ close() [3/4]

void websocket_endpoint::close ( int id,
websocketpp::close::status::value code,
std::string reason )
inline

Definition at line 185 of file step5.cpp.

185 {
186 websocketpp::lib::error_code ec;
187
188 con_list::iterator metadata_it = m_connection_list.find(id);
189 if (metadata_it == m_connection_list.end()) {
190 std::cout << "> No connection found with id " << id << std::endl;
191 return;
192 }
193
194 m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
195 if (ec) {
196 std::cout << "> Error initiating close: " << ec.message() << std::endl;
197 }
198 }
Here is the call graph for this function:

◆ close() [4/4]

void websocket_endpoint::close ( int id,
websocketpp::close::status::value code,
std::string reason )
inline

Definition at line 210 of file step6.cpp.

210 {
211 websocketpp::lib::error_code ec;
212
213 con_list::iterator metadata_it = m_connection_list.find(id);
214 if (metadata_it == m_connection_list.end()) {
215 std::cout << "> No connection found with id " << id << std::endl;
216 return;
217 }
218
219 m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
220 if (ec) {
221 std::cout << "> Error initiating close: " << ec.message() << std::endl;
222 }
223 }
Here is the call graph for this function:

◆ connect() [1/5]

int websocket_endpoint::connect ( std::string const & uri)
inline

Definition at line 147 of file scratch_client.cpp.

147 {
148 websocketpp::lib::error_code ec;
149
150 client::connection_ptr con = m_endpoint.get_connection(uri, ec);
151
152 if (ec) {
153 std::cout << "> Connect initialization error: " << ec.message() << std::endl;
154 return -1;
155 }
156
157 int new_id = m_next_id++;
158 connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
159 m_connection_list[new_id] = metadata_ptr;
160
161 con->set_open_handler(websocketpp::lib::bind(
163 metadata_ptr,
164 &m_endpoint,
165 websocketpp::lib::placeholders::_1
166 ));
167 con->set_fail_handler(websocketpp::lib::bind(
169 metadata_ptr,
170 &m_endpoint,
171 websocketpp::lib::placeholders::_1
172 ));
173 con->set_close_handler(websocketpp::lib::bind(
175 metadata_ptr,
176 &m_endpoint,
177 websocketpp::lib::placeholders::_1
178 ));
179
180 m_endpoint.connect(con);
181
182 return new_id;
183 }
void on_fail(client *c, websocketpp::connection_hdl hdl)
void on_open(client *c, websocketpp::connection_hdl hdl)
void on_close(client *c, websocketpp::connection_hdl hdl)
websocketpp::lib::shared_ptr< connection_metadata > ptr
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [2/5]

int websocket_endpoint::connect ( std::string const & uri)
inline

Definition at line 166 of file utility_client.cpp.

166 {
167 websocketpp::lib::error_code ec;
168
169 client::connection_ptr con = m_endpoint.get_connection(uri, ec);
170
171 if (ec) {
172 std::cout << "> Connect initialization error: " << ec.message() << std::endl;
173 return -1;
174 }
175
176 int new_id = m_next_id++;
177 connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
178 m_connection_list[new_id] = metadata_ptr;
179
180 con->set_open_handler(websocketpp::lib::bind(
182 metadata_ptr,
183 &m_endpoint,
184 websocketpp::lib::placeholders::_1
185 ));
186 con->set_fail_handler(websocketpp::lib::bind(
188 metadata_ptr,
189 &m_endpoint,
190 websocketpp::lib::placeholders::_1
191 ));
192 con->set_close_handler(websocketpp::lib::bind(
194 metadata_ptr,
195 &m_endpoint,
196 websocketpp::lib::placeholders::_1
197 ));
198 con->set_message_handler(websocketpp::lib::bind(
200 metadata_ptr,
201 websocketpp::lib::placeholders::_1,
202 websocketpp::lib::placeholders::_2
203 ));
204
205 m_endpoint.connect(con);
206
207 return new_id;
208 }
void on_message(websocketpp::connection_hdl, client::message_ptr msg)
Here is the call graph for this function:

◆ connect() [3/5]

int websocket_endpoint::connect ( std::string const & uri)
inline

Definition at line 103 of file step4.cpp.

103 {
104 websocketpp::lib::error_code ec;
105
106 client::connection_ptr con = m_endpoint.get_connection(uri, ec);
107
108 if (ec) {
109 std::cout << "> Connect initialization error: " << ec.message() << std::endl;
110 return -1;
111 }
112
113 int new_id = m_next_id++;
114 connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
115 m_connection_list[new_id] = metadata_ptr;
116
117 con->set_open_handler(websocketpp::lib::bind(
119 metadata_ptr,
120 &m_endpoint,
121 websocketpp::lib::placeholders::_1
122 ));
123 con->set_fail_handler(websocketpp::lib::bind(
125 metadata_ptr,
126 &m_endpoint,
127 websocketpp::lib::placeholders::_1
128 ));
129
130 m_endpoint.connect(con);
131
132 return new_id;
133 }
Here is the call graph for this function:

◆ connect() [4/5]

int websocket_endpoint::connect ( std::string const & uri)
inline

Definition at line 147 of file step5.cpp.

147 {
148 websocketpp::lib::error_code ec;
149
150 client::connection_ptr con = m_endpoint.get_connection(uri, ec);
151
152 if (ec) {
153 std::cout << "> Connect initialization error: " << ec.message() << std::endl;
154 return -1;
155 }
156
157 int new_id = m_next_id++;
158 connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
159 m_connection_list[new_id] = metadata_ptr;
160
161 con->set_open_handler(websocketpp::lib::bind(
163 metadata_ptr,
164 &m_endpoint,
165 websocketpp::lib::placeholders::_1
166 ));
167 con->set_fail_handler(websocketpp::lib::bind(
169 metadata_ptr,
170 &m_endpoint,
171 websocketpp::lib::placeholders::_1
172 ));
173 con->set_close_handler(websocketpp::lib::bind(
175 metadata_ptr,
176 &m_endpoint,
177 websocketpp::lib::placeholders::_1
178 ));
179
180 m_endpoint.connect(con);
181
182 return new_id;
183 }
Here is the call graph for this function:

◆ connect() [5/5]

int websocket_endpoint::connect ( std::string const & uri)
inline

Definition at line 166 of file step6.cpp.

166 {
167 websocketpp::lib::error_code ec;
168
169 client::connection_ptr con = m_endpoint.get_connection(uri, ec);
170
171 if (ec) {
172 std::cout << "> Connect initialization error: " << ec.message() << std::endl;
173 return -1;
174 }
175
176 int new_id = m_next_id++;
177 connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
178 m_connection_list[new_id] = metadata_ptr;
179
180 con->set_open_handler(websocketpp::lib::bind(
182 metadata_ptr,
183 &m_endpoint,
184 websocketpp::lib::placeholders::_1
185 ));
186 con->set_fail_handler(websocketpp::lib::bind(
188 metadata_ptr,
189 &m_endpoint,
190 websocketpp::lib::placeholders::_1
191 ));
192 con->set_close_handler(websocketpp::lib::bind(
194 metadata_ptr,
195 &m_endpoint,
196 websocketpp::lib::placeholders::_1
197 ));
198 con->set_message_handler(websocketpp::lib::bind(
200 metadata_ptr,
201 websocketpp::lib::placeholders::_1,
202 websocketpp::lib::placeholders::_2
203 ));
204
205 m_endpoint.connect(con);
206
207 return new_id;
208 }
Here is the call graph for this function:

◆ get_metadata() [1/5]

connection_metadata::ptr websocket_endpoint::get_metadata ( int id) const
inline

Definition at line 200 of file scratch_client.cpp.

200 {
201 con_list::const_iterator metadata_it = m_connection_list.find(id);
202 if (metadata_it == m_connection_list.end()) {
204 } else {
205 return metadata_it->second;
206 }
207 }
Here is the caller graph for this function:

◆ get_metadata() [2/5]

connection_metadata::ptr websocket_endpoint::get_metadata ( int id) const
inline

Definition at line 243 of file utility_client.cpp.

243 {
244 con_list::const_iterator metadata_it = m_connection_list.find(id);
245 if (metadata_it == m_connection_list.end()) {
247 } else {
248 return metadata_it->second;
249 }
250 }

◆ get_metadata() [3/5]

connection_metadata::ptr websocket_endpoint::get_metadata ( int id) const
inline

Definition at line 135 of file step4.cpp.

135 {
136 con_list::const_iterator metadata_it = m_connection_list.find(id);
137 if (metadata_it == m_connection_list.end()) {
139 } else {
140 return metadata_it->second;
141 }
142 }

◆ get_metadata() [4/5]

connection_metadata::ptr websocket_endpoint::get_metadata ( int id) const
inline

Definition at line 200 of file step5.cpp.

200 {
201 con_list::const_iterator metadata_it = m_connection_list.find(id);
202 if (metadata_it == m_connection_list.end()) {
204 } else {
205 return metadata_it->second;
206 }
207 }

◆ get_metadata() [5/5]

connection_metadata::ptr websocket_endpoint::get_metadata ( int id) const
inline

Definition at line 243 of file step6.cpp.

243 {
244 con_list::const_iterator metadata_it = m_connection_list.find(id);
245 if (metadata_it == m_connection_list.end()) {
247 } else {
248 return metadata_it->second;
249 }
250 }

◆ send() [1/2]

void websocket_endpoint::send ( int id,
std::string message )
inline

Definition at line 225 of file utility_client.cpp.

225 {
226 websocketpp::lib::error_code ec;
227
228 con_list::iterator metadata_it = m_connection_list.find(id);
229 if (metadata_it == m_connection_list.end()) {
230 std::cout << "> No connection found with id " << id << std::endl;
231 return;
232 }
233
234 m_endpoint.send(metadata_it->second->get_hdl(), message, websocketpp::frame::opcode::text, ec);
235 if (ec) {
236 std::cout << "> Error sending message: " << ec.message() << std::endl;
237 return;
238 }
239
240 metadata_it->second->record_sent_message(message);
241 }
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send() [2/2]

void websocket_endpoint::send ( int id,
std::string message )
inline

Definition at line 225 of file step6.cpp.

225 {
226 websocketpp::lib::error_code ec;
227
228 con_list::iterator metadata_it = m_connection_list.find(id);
229 if (metadata_it == m_connection_list.end()) {
230 std::cout << "> No connection found with id " << id << std::endl;
231 return;
232 }
233
234 m_endpoint.send(metadata_it->second->get_hdl(), message, websocketpp::frame::opcode::text, ec);
235 if (ec) {
236 std::cout << "> Error sending message: " << ec.message() << std::endl;
237 return;
238 }
239
240 metadata_it->second->record_sent_message(message);
241 }
Here is the call graph for this function:

The documentation for this class was generated from the following files: