picloud add server logics

This commit is contained in:
2021-04-06 17:49:07 +03:00
parent be0db84147
commit fcf9f0f80e
9 changed files with 178 additions and 26 deletions

View File

@@ -61,6 +61,14 @@ void PICloud::TCP::sendConnected(PIEthernet * eth, uint client_id) {
}
void PICloud::TCP::sendDisconnected(PIEthernet * eth, uint client_id) {
header.type = PICloud::TCP::Disconnect;
PIByteArray ba;
ba << header << client_id;
eth->send(ba);
}
void PICloud::TCP::sendData(PIEthernet * eth, const PIByteArray & data) {
header.type = PICloud::TCP::Data;
PIByteArray ba;
@@ -71,6 +79,16 @@ void PICloud::TCP::sendData(PIEthernet * eth, const PIByteArray & data) {
}
int PICloud::TCP::sendData(PIEthernet * eth, const PIByteArray & data, uint client_id) {
header.type = PICloud::TCP::Data;
PIByteArray ba;
ba << header << client_id;
ba.append(data);
if (eth->send(ba)) return data.size_s();
else return -1;
}
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> PICloud::TCP::parseHeader(PIByteArray & ba) {
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> ret;
ret.first = Invalid;
@@ -88,11 +106,6 @@ PIPair<PICloud::TCP::Type, PICloud::TCP::Role> PICloud::TCP::parseHeader(PIByteA
PIByteArray PICloud::TCP::parseData(PIByteArray & ba) {
if (header.role == Server) {
PIString client;
ba >> client;
return ba;
}
if (header.role == Client) {
return ba;
}
@@ -100,8 +113,33 @@ PIByteArray PICloud::TCP::parseData(PIByteArray & ba) {
}
PIString PICloud::TCP::parseConnect(PIByteArray & ba) {
PIPair<uint, PIByteArray> PICloud::TCP::parseDataServer(PIByteArray & ba) {
PIPair<uint, PIByteArray> ret;
ret.first = 0;
if (header.role == Server) {
ba >> ret.first;
ret.second = ba;
}
return ret;
}
PIString PICloud::TCP::parseConnect_d(PIByteArray & ba) {
PIString ret;
ba >> ret;
return ret;
}
uint PICloud::TCP::parseConnect(PIByteArray & ba) {
uint ret;
ba >> ret;
return ret;
}
uint PICloud::TCP::parseDisconnect(PIByteArray & ba) {
uint ret;
ba >> ret;
return ret;
}