diff --git a/examples/Client/Client.ino b/examples/Client/Client.ino index a57eb17..d5fbded 100644 --- a/examples/Client/Client.ino +++ b/examples/Client/Client.ino @@ -36,6 +36,11 @@ void onSend(){ Serial.println("Sending Successfully"); } + +// #define TEST_1 +#define TEST_2 + + void setup() { Serial.begin(115200); @@ -54,8 +59,10 @@ void setup() client.setOnSendSuccess(onSend); } - +#ifdef TEST_2 +//* for many packets bool dataReady = false; +#endif void loop() { @@ -74,10 +81,27 @@ void loop() Serial.println("connectNonBlock"); client.startConnection(serverIP, SERVER_PORT); +#ifdef TEST_1 + //* for single packets + client.dataWrite((uint8_t *)&packetCounter, sizeof(packetCounter)); + Serial.print("Sending packet: "); + for (size_t j = 0; j < sizeof(packetCounter); j++) + { + Serial.print(((uint8_t *)&packetCounter)[j], HEX); + Serial.print(" "); + } + Serial.println(); + packetCounter++; +#endif +#ifdef TEST_2 + //* for many packets dataReady = true; +#endif } - if(dataReady && client.isConnected()) +#ifdef TEST_2 + //* for many packets + if(dataReady && client.isConnected()) //* check connection { for (size_t i = 0; i < 3; i++) { @@ -95,4 +119,5 @@ void loop() } dataReady = false; } +#endif } \ No newline at end of file diff --git a/src/EthernetOverride/TCP.cpp b/src/EthernetOverride/TCP.cpp index 4512829..b924dcc 100644 --- a/src/EthernetOverride/TCP.cpp +++ b/src/EthernetOverride/TCP.cpp @@ -263,17 +263,21 @@ bool EthernetMaketClient::dataWrite(){ } lastActivityTime = millis(); } + if(ret){ + onSendSuccess(); + } return ret; } -bool EthernetMaketClient::dataWrite(uint8_t* data, uint16_t dataSize, bool override) { +void EthernetMaketClient::dataWrite(uint8_t* data, uint16_t dataSize, bool override) { if (this->dataSize == 0 || override) { this->dataPtr = data; this->dataSize = dataSize; - return dataWrite(); + if(isConnected()){ + dataWrite(); + } } else { Serial.println("Data buffer is not empty. Write operation is ignored."); - return false; } } @@ -324,6 +328,5 @@ void EthernetMaketClient::startConnection(IPAddress ip, uint16_t port, bool nonB dstIP = ip; dstPort = port; isNonBlocking = nonBlock; - connectNonBlock(dstIP, dstPort); connectStatus = CONNECT_START; }; diff --git a/src/EthernetOverride/TCP.h b/src/EthernetOverride/TCP.h index a01158b..36752b5 100644 --- a/src/EthernetOverride/TCP.h +++ b/src/EthernetOverride/TCP.h @@ -38,7 +38,7 @@ public: ConnectionStatusSimple connectNonBlock(IPAddress ip, uint16_t port); void startConnection(IPAddress ip, uint16_t port, bool nonBlock = true); - bool dataWrite(uint8_t* data, uint16_t dataSize, bool override = false); + void dataWrite(uint8_t* data, uint16_t dataSize, bool override = false); // bool send(uint8_t* data, uint16_t dataSize, IPAddress ip, uint16_t port); void disconnect();