picloud add server logics
This commit is contained in:
@@ -40,7 +40,9 @@ void CloudServer::printStatus() {
|
||||
for (auto c: clients) {
|
||||
piCout << " " << c->address() << c->clientId();
|
||||
}
|
||||
for (auto c: clients) c->sendData(PIByteArray::fromHex("000000"));
|
||||
server->sendData(PIByteArray::fromHex("000000"));
|
||||
for (auto c: clients) {
|
||||
c->sendData(PIByteArray::fromHex("000000"));
|
||||
server->sendDataToClient(PIByteArray::fromHex("000000"), c->clientId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,14 @@ void DispatcherClient::sendConnected() {
|
||||
|
||||
|
||||
void DispatcherClient::sendData(const PIByteArray & data) {
|
||||
tcp.sendData(eth, data);
|
||||
if (tcp.role() == PICloud::TCP::Client) tcp.sendData(eth, data);
|
||||
else piCoutObj << "error sendData, invalid role";
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id) {
|
||||
if (tcp.role() == PICloud::TCP::Server) tcp.sendData(eth, data, client_id);
|
||||
else piCoutObj << "error sendDataToClient, invalid role";
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +79,7 @@ void DispatcherClient::readed(uchar *data, int size) {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect: {
|
||||
tcp.setRole(hdr.second);
|
||||
PIString sn = tcp.parseConnect(ba);
|
||||
PIString sn = tcp.parseConnect_d(ba);
|
||||
if (hdr.second == PICloud::TCP::Server) registerServer(sn, this);
|
||||
if (hdr.second == PICloud::TCP::Client) registerClient(sn, this);
|
||||
return;}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
void close();
|
||||
void sendConnected();
|
||||
void sendData(const PIByteArray & data);
|
||||
void sendDataToClient(const PIByteArray & data, uint client_id);
|
||||
PIString address();
|
||||
uint clientId() const {return client_id;}
|
||||
EVENT1(disconnectEvent, DispatcherClient *, client)
|
||||
|
||||
Reference in New Issue
Block a user