some PICloud and PIEthernet fixes

This commit is contained in:
Бычков Андрей
2022-11-09 17:04:13 +03:00
parent d3dd3fb32b
commit 8738043dce
6 changed files with 20 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ int main(int argc, char * argv[]) {
PICloudClient c("127.0.0.1:10101");
// c.setReopenEnabled(true);
PICloudServer s("127.0.0.1:10101");
PIVector<PICloudServer::Client *> clients;
auto clients = new PIVector<PICloudServer::Client *>();
CONNECTL(&tm, tickEvent, ([&](void *, int){
if (c.isConnected()) {
PIString str = "ping";
@@ -19,7 +19,7 @@ int main(int argc, char * argv[]) {
c.write(str.toByteArray());
}
if (s.isThreadedRead()) {
for (auto cl : clients) {
for (auto cl : *clients) {
if (cl->isOpened()) {
PIString str = "ping_S";
piCout << "[Server] send to" << cl << ":" << str;
@@ -40,7 +40,7 @@ int main(int argc, char * argv[]) {
CONNECTL(&c, disconnected, ([](){piCout << "disconnected";}));
CONNECTL(&s, newConnection, ([&](PICloudServer::Client * cl){
piCout << "[Server] new client:" << cl;
clients << cl;
clients->append(cl);
CONNECTL(cl, threadedReadEvent, ([cl, &rnd](const uchar * readed, ssize_t size){
PIByteArray ba(readed, size);
PIString str = PIString(ba);
@@ -53,7 +53,7 @@ int main(int argc, char * argv[]) {
CONNECTL(cl, closed, ([&clients, cl](){
piCout << "[Server] client closed ..." << cl;
cl->stop();
clients.removeAll(cl);
clients->removeAll(cl);
piCout << "[Server] client closed ok" << cl;
}));
cl->startThreadedRead();