SNode.C
Loading...
Searching...
No Matches
echoclient.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 "core/SNodeC.h"
21#include "model/clients.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 SocketClient = apps::echo::model::STREAM::EchoSocketClient;
35 using SocketAddress = SocketClient::SocketAddress;
36 const SocketClient client = apps::echo::model::STREAM::getClient();
37
38 client.connect(
39 [instanceName = client.getConfig().getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) {
40 switch (state) {
41 case core::socket::State::OK:
42 VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'";
43 break;
44 case core::socket::State::DISABLED:
45 VLOG(1) << instanceName << ": disabled";
46 break;
47 case core::socket::State::ERROR:
48 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
49 break;
50 case core::socket::State::FATAL:
51 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
52 break;
53 }
54 });
55 /*
56 client.connect([](const SocketAddress& socketAddress, const core::socket::State& state) {
57 switch (state) {
58 case core::socket::State::OK:
59 VLOG(1) << "echoclient: connected to '" << socketAddress.toString() << "'" << "'";
60 break;
61 case core::socket::State::DISABLED:
62 VLOG(1) << "echoclient: disabled";
63 break;
64 case core::socket::State::ERROR:
65 VLOG(1) << "echoclientt: error occurred";
66 break;
67 case core::socket::State::FATAL:
68 VLOG(1) << "echoclient: fatal error occurred";
69 break;
70 }
71 });
72 */
73 return core::SNodeC::start();
74}
75
76/*
77#if (NET_TYPE == IN) // in
78#if (STREAM_TYPE == LEGACY)
79 client.connect("localhost", 8080, [](int errnum) {
80#elif (STREAM_TYPE == TLS)
81 client.connect("localhost", 8088, [](int errnum) {
82#endif
83#elif (NET_TYPE == IN6) // in6
84#if (STREAM_TYPE == LEGACY)
85 client.connect("localhost", 8080, [](int errnum) {
86#elif (STREAM_TYPE == TLS)
87 client.connect("localhost", 8088, [](int errnum) {
88#endif
89#elif (NET_TYPE == L2) // l2
90 // ATLAS: 10:3D:1C:AC:BA:9C
91 // TITAN: A4:B1:C1:2C:82:37
92 // USB: 44:01:BB:A3:63:32
93
94 // client.connect("A4:B1:C1:2C:82:37", 0x1023, "44:01:BB:A3:63:32", [](int errnum) {
95 client.connect("10:3D:1C:AC:BA:9C", 0x1023, "44:01:BB:A3:63:32", [](int errnum) {
96#elif (NET_TYPE == RC) // rf
97 // client.connect("A4:B1:C1:2C:82:37", 1, "44:01:BB:A3:63:32", [](int errnum) {
98 client.connect("10:3D:1C:AC:BA:9C", 1, "44:01:BB:A3:63:32", [](int errnum) {
99#elif (NET_TYPE == UN) // un
100 client.connect("/tmp/testme", [](int errnum) {
101#endif
102
103 if (errnum < 0) {
104 PLOG(ERROR) << "OnError";
105 } else if (errnum > 0) {
106 errno = errnum;
107 PLOG(ERROR) << "OnError: " << socketAddress.toString();
108 } else {
109 VLOG(1) << "snode.c connecting to " << socketAddress.toString();
110 }
111
112#ifdef NET_TYPE
113 });
114#endif
115*/
int main(int argc, char *argv[])