first try, works

This commit is contained in:
2024-09-11 10:18:45 +03:00
parent 16a818c95e
commit 0d94699206
9 changed files with 441 additions and 30 deletions

View File

@@ -1,4 +1,6 @@
#include "pibytearray.h"
#include "piclient_server_client.h"
#include "piclient_server_server.h"
#include "picodeparser.h"
#include "piiostream.h"
#include "pijson.h"
@@ -16,22 +18,51 @@ enum MyEvent {
meIntString,
};
PITimeMeasurer tm;
std::atomic_int cnt = {0};
void tfunc(int delim) {
// piCout << "tick with delimiter" << delim;
++cnt;
};
void tfunc4(int delim) {
piCout << "tick4 with delimiter" << delim;
PIKbdListener kbd;
class MyClient: public PIClientServer::Client {
protected:
void readed(PIByteArray data) override { piCout << "readed" << (data.size()); }
void connected() override {
send_thread.start(
[this] {
// write((PIString::fromNumber(++counter)).toUTF8());
PIByteArray ba(64_MiB);
write(ba);
},
2_Hz);
}
PIThread send_thread;
int counter = 0;
};
int main(int argc, char * argv[]) {
uint v = 0xaabbccdd;
piCout << Hex << v << piChangedEndian(v);
piChangeEndianBinary(&v, sizeof(v));
piCout << Hex << v << piChangedEndian(v);
kbd.enableExitCapture();
piCout << argc;
PIClientServer::Server * s = nullptr;
PIClientServer::Client * c = nullptr;
if (argc > 1) {
// server
s = new PIClientServer::Server();
s->setClientFactory([] { return new MyClient(); });
s->listenAll(12345);
} else {
// client
c = new MyClient();
c->createNew();
c->connect(PINetworkAddress::resolve("127.0.0.1", 12345));
}
WAIT_FOR_EXIT;
piDeleteSafety(s);
piDeleteSafety(c);
return 0;
/*PIPackedTCP * tcp_s =
PIIODevice::createFromFullPath("ptcp://s::8000")->cast<PIPackedTCP>(); // new PIPackedTCP(PIPackedTCP::Server, {"0.0.0.0:8000"});