SNode.C
Loading...
Searching...
No Matches
legacy Namespace Reference

Typedefs

using SocketClient = net::in::stream::legacy::SocketClient<apps::http::SimpleSocketProtocolFactory>
 
using SocketAddress = SocketClient::SocketAddress
 
using SocketConnection = SocketClient::SocketConnection
 

Functions

SocketClient getLegacyClient ()
 

Typedef Documentation

◆ SocketAddress

◆ SocketClient

◆ SocketConnection

Function Documentation

◆ getLegacyClient()

SocketClient legacy::getLegacyClient ( )

Definition at line 264 of file httplowlevelclient.cpp.

264 {
265 SocketClient legacyClient(
266 "legacy",
267 [](SocketConnection* socketConnection) { // OnConnect
268 VLOG(1) << "OnConnect";
269
270 VLOG(1) << "\tServer: " << socketConnection->getRemoteAddress().toString();
271 VLOG(1) << "\tClient: " << socketConnection->getLocalAddress().toString();
272 },
273 [](SocketConnection* socketConnection) { // onConnected
274 VLOG(1) << "OnConnected";
275
276 socketConnection->sendToPeer("GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n"); // Connection: close\r\n\r\n");
277 },
278 [](SocketConnection* socketConnection) { // onDisconnect
279 VLOG(1) << "OnDisconnect";
280
281 VLOG(1) << "\tServer: " << socketConnection->getRemoteAddress().toString();
282 VLOG(1) << "\tClient: " << socketConnection->getLocalAddress().toString();
283 });
284
285 SocketAddress remoteAddress("localhost", 8080);
286
287 remoteAddress.init();
288
289 VLOG(1) << "###############': " << remoteAddress.getCanonName();
290 VLOG(1) << "###############': " << remoteAddress.toString();
291
292 legacyClient.connect(remoteAddress,
293 [instanceName = legacyClient.getConfig().getInstanceName()](
294 const tls::SocketAddress& socketAddress,
295 const core::socket::State& state) { // example.com:81 simulate connnect timeout
296 switch (state) {
297 case core::socket::State::OK:
298 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
299 break;
300 case core::socket::State::DISABLED:
301 VLOG(1) << instanceName << ": disabled";
302 break;
303 case core::socket::State::ERROR:
304 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
305 break;
306 case core::socket::State::FATAL:
307 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
308 break;
309 }
310 });
311
312 return legacyClient;
313 }
Client::SocketConnection SocketConnection
Definition clients.h:66
SocketClient::SocketConnection SocketConnection
SocketClient::SocketAddress SocketAddress