-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.cpp
More file actions
66 lines (56 loc) · 3.04 KB
/
Copy pathclient.cpp
File metadata and controls
66 lines (56 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "ClientContext.h" // IWYU pragma: keep
#include <SemanticLog.h>
#include <core/SNodeC.h>
#include <net/in/stream/tls/SocketClient.h>
#include <net/un/stream/legacy/SocketClient.h>
int main(int argc, char* argv[]) {
using Client = net::un::stream::legacy::SocketClient<ClientContextFactory>;
using SocketConnection = Client::SocketConnection;
core::SNodeC::init(argc, argv);
Client client(
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
client.connect("/tmp/testsocket", [](const Client::SocketAddress& socketAddress, int errnum) -> void {
if (errnum == 0) {
snode::semantic::appLog().info() << "Client connected to " << socketAddress.toString();
} else {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "Client failed to connect to " << socketAddress.toString();
}
});
using ClientTLS = net::in::stream::tls::SocketClient<ClientContextFactory>;
using SocketConnectionTLS = ClientTLS::SocketConnection;
ClientTLS clienttls(
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});
clienttls.getConfig()
.setCertChain("/home/voc/projects/ServerClient/Client-End-Entity.pem")
.setCertKey("/home/voc/projects/ServerClient/Client-End-Entity-Key.pem")
.setCertKeyPassword("pentium5")
.setCaCertFile("/home/voc/projects/ServerClient/VolkerChristianRootCA.pem");
clienttls.connect("localhost", 8082, [](const ClientTLS::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
snode::semantic::appLog().info() << "snode.c connecting to " << socketAddress.toString();
}
});
return core::SNodeC::start();
}