add PIClientServer::Config, common configuration type for both sides, stream packer and encryption settings

This commit is contained in:
2024-09-13 11:08:32 +03:00
parent 996b7ea403
commit 17b902ebcc
8 changed files with 125 additions and 25 deletions

View File

@@ -27,7 +27,7 @@ public:
~MyServerClient() { send_thread.stopAndWait(); }
protected:
// void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
// void aboutDelete() override { piCout << "aboutDelete"; }
// void disconnected() override { piCout << "disconnected"; }
void connected() override {
@@ -50,7 +50,7 @@ public:
~MyClient() { send_thread.stopAndWait(); }
protected:
// void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
void disconnected() override { piCout << "disconnected"; }
void connected() override {
piCout << "connected";
@@ -101,7 +101,7 @@ int main(int argc, char * argv[]) {
piCout << "Server";
s = new PIClientServer::Server();
s->setClientFactory([] { return new MyServerClient(); });
s->enableSymmetricEncryption("1122334455667788"_hex);
s->configuration().enableSymmetricEncryption("1122334455667788"_hex);
s->listenAll(12345);
s_thread->start(
[s] {
@@ -110,17 +110,17 @@ int main(int argc, char * argv[]) {
s->forEachClient([&i](PIClientServer::ServerClient * c) {
// piCout << "client" << ++i << c;
c->write(PIByteArray(1_KiB));
c->close();
// c->close();
// piMSleep(200);
});
},
1._Hz);
} else {
piCout << "Client";
piForTimes(20) {
piForTimes(2) {
piMSleep(25);
auto c = new MyClient();
c->enableSymmetricEncryption("1122334455667788"_hex);
c->configuration().enableSymmetricEncryption("1122334455667788"_hex);
c->connect(PINetworkAddress::resolve("127.0.0.1", 12345));
cv << c;
}