PIClout data send and receive test
This commit is contained in:
@@ -30,9 +30,9 @@ void DispatcherClient::close() {
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::sendConnected() {
|
||||
piCoutObj << "sendConnected";
|
||||
tcp.sendConnected(1);
|
||||
void DispatcherClient::sendConnected(uint client_id) {
|
||||
//piCoutObj << "sendConnected";
|
||||
tcp.sendConnected(client_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,13 @@ void DispatcherClient::sendDataToClient(const PIByteArray & data, uint client_id
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::authorise(bool ok) {
|
||||
authorised = ok;
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::disconnected(bool withError) {
|
||||
piCoutObj << "client disconnected" << eth->sendAddress();
|
||||
//piCoutObj << "client disconnected" << eth->sendAddress();
|
||||
disconnectEvent(this);
|
||||
}
|
||||
|
||||
@@ -62,18 +67,30 @@ void DispatcherClient::readed(PIByteArray & ba) {
|
||||
return;
|
||||
}
|
||||
if (authorised) {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect:
|
||||
return;
|
||||
case PICloud::TCP::Disconnect:
|
||||
disconnected(false);
|
||||
return;
|
||||
case PICloud::TCP::Data:
|
||||
dataReaded(tcp.parseData(ba));
|
||||
return;
|
||||
default:
|
||||
disconnected(true);
|
||||
return;
|
||||
if (hdr.second == tcp.role()) {
|
||||
switch (hdr.first) {
|
||||
case PICloud::TCP::Connect:
|
||||
return;
|
||||
case PICloud::TCP::Disconnect:
|
||||
disconnected(false);
|
||||
return;
|
||||
case PICloud::TCP::Data:
|
||||
// piCoutObj << "TCP::Data";
|
||||
if (tcp.role() == PICloud::TCP::Client) {
|
||||
PIByteArray data = tcp.parseData(ba);
|
||||
if (!data.isEmpty()) dataReaded(data);
|
||||
else piCoutObj << "invalid data from client";
|
||||
}
|
||||
if (tcp.role() == PICloud::TCP::Server) {
|
||||
PIPair<uint, PIByteArray> dp = tcp.parseDataServer(ba);
|
||||
if (!dp.second.isEmpty()) dataReadedServer(dp.first, dp.second);
|
||||
else piCoutObj << "invalid data from server";
|
||||
}
|
||||
return;
|
||||
default:
|
||||
//disconnected(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (hdr.first) {
|
||||
@@ -82,7 +99,7 @@ void DispatcherClient::readed(PIByteArray & 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;}
|
||||
return;}
|
||||
case PICloud::TCP::Disconnect:
|
||||
disconnected(false);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user