SNode.C
Loading...
Searching...
No Matches
httpclient.cpp
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "apps/http/model/clients.h"
21#include "core/SNodeC.h"
22
23#ifndef DOXYGEN_SHOULD_SKIP_THIS
24
25#include "log/Logger.h"
26
27#include <string>
28
29#endif /* DOXYGEN_SHOULD_SKIP_THIS */
30
31int main(int argc, char* argv[]) {
32 core::SNodeC::init(argc, argv);
33
34 using Client = apps::http::STREAM::Client;
35
36 const Client client = apps::http::STREAM::getClient();
37
38 client.connect([instanceName = client.getConfig().getInstanceName()](
39 const core::socket::SocketAddress& socketAddress,
40 const core::socket::State& state) { // example.com:81 simulate connnect timeout
41 switch (state) {
42 case core::socket::State::OK:
43 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
44 break;
45 case core::socket::State::DISABLED:
46 VLOG(1) << instanceName << ": disabled";
47 break;
48 case core::socket::State::ERROR:
49 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
50 break;
51 case core::socket::State::FATAL:
52 VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
53 break;
54 }
55 });
56
57 return core::SNodeC::start();
58}
59
60/*
61#if (NET_TYPE == IN) // in
62#if (STREAM_TYPE == LEGACY)
63 client.connect("localhost", 8080, [](const SocketAddress& socketAddress, const core::socket::State& state) {
64#elif (STREAM_TYPE == TLS)
65 client.connect("localhost", 8088, [](const SocketAddress& socketAddress, const core::socket::State& state) {
66#endif
67#elif (NET_TYPE == IN6) // in6
68#if (STREAM_TYPE == LEGACY)
69 client.connect("localhost", 8080, [](const SocketAddress& socketAddress, const core::socket::State& state) {
70#elif (STREAM_TYPE == TLS)
71 client.connect("localhost", 8088, [](const SocketAddress& socketAddress, const core::socket::State& state) {
72#endif
73#elif (NET_TYPE == L2) // l2
74 // ATLAS: 10:3D:1C:AC:BA:9C
75 // TITAN: A4:B1:C1:2C:82:37
76 // USB: 44:01:BB:A3:63:32
77
78 // client.connect("A4:B1:C1:2C:82:37", 0x1023, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const core::socket::State&
79state) { client.connect("10:3D:1C:AC:BA:9C", 0x1023, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const
80core::socket::State& state) { #elif (NET_TYPE == RC) // rf
81 // client.connect("A4:B1:C1:2C:82:37", 1, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const core::socket::State& state)
82{ client.connect("10:3D:1C:AC:BA:9C", 1, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const core::socket::State&
83state) { #elif (NET_TYPE == UN) // un client.connect("/tmp/testme", [](const SocketAddress& socketAddress, const
84core::socket::State& state) { #endif if (errnum != 0) { PLOG(ERROR) << "OnError: " << errnum; } else { VLOG(1) << "snode.c
85connecting to " << socketAddress.toString();
86 }
87
88#ifdef NET_TYPE
89 });
90#endif
91*/
int main(int argc, char *argv[])