diff --git a/CHANGELOG.md b/CHANGELOG.md index 4abed42d1e66b35d091d186f21a5c7351b1184a7..f7544c8297f5e1c9555389f93838f8a6e3dc5da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.2 -- ArkTs语法规则整改 +- ArkTs新语法适配 - 解决发送多次请求,回调结果相互影响的问题 ## 2.0.1 diff --git a/README.md b/README.md index 6d38fdf3728ab0326eb9c6c0b7fd3c0f8ff2c397..eeb399815c3fb723a004abafb65590572fff56dc 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ For details about the environment configuration, see [Installing the OpenHarmony // Enable the native log feature. CoapClient.setNativeLogOpen(true); // Initiate a CoAP GET request. Replace this.coapUri with the actual URL. +// Each coapClient corresponds to a COAP request task and cannot be reused. let coapClient = new CoapClient(); let coapGet = coapClient.request(this.coapUri, CoapRequestMethod.GET, CoapRequestType.COAP_MESSAGE_CON); console.log("libcoap get test"); @@ -69,6 +70,7 @@ coapClient.setFormat(ContentFormat.PLAIN); // Set the data to be transparently transmitted. coapClient.setPayload("this is put test payload"); // Initiate a CoAP PUT request. Replace this.coapUri with the actual URL. +// Each coapClient corresponds to a COAP request task and cannot be reused. let coapPut = coapClient.request(this.coapUri, CoapRequestMethod.PUT, CoapRequestType.COAP_MESSAGE_CON); console.log("libcoap put test"); // Asynchronous callback of the CoAP GET request diff --git a/README_zh.md b/README_zh.md index 55ebda3b1f04a528da9502c1ed0f8dba49b5d9cc..4c9599a867ed9bace782814cd6f564e82db9b8d9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -41,6 +41,7 @@ OpenHarmony ohpm // 打开native log开关 CoapClient.setNativeLogOpen(true); // 发起coap get请求,注意this.coapUri请使用者换成真实的url +// 每一个CoapClient对应一个COAP请求任务,不可复用 let coapClient = new CoapClient(); let coapGet = coapClient.request(this.coapUri, CoapRequestMethod.GET, CoapRequestType.COAP_MESSAGE_CON); console.log("libcoap get test"); @@ -68,6 +69,7 @@ coapClient.setFormat(ContentFormat.PLAIN); //设置透传数据 coapClient.setPayload("this is put test payload"); // 发起coap put请求,注意this.coapUri请使用者换成真实的url +// 每一个CoapClient对应一个COAP请求任务,不可复用 let coapPut = coapClient.request(this.coapUri, CoapRequestMethod.PUT, CoapRequestType.COAP_MESSAGE_CON); console.log("libcoap put test"); //coap get请求异步回调 diff --git a/libcoap/src/main/cpp/coap-client.cpp b/libcoap/src/main/cpp/coap-client.cpp index 6950baf5c933f91d164d011d543ef2d94fa0f1b7..19589f595e8b93fa997937a45a782607730dfaf0 100644 --- a/libcoap/src/main/cpp/coap-client.cpp +++ b/libcoap/src/main/cpp/coap-client.cpp @@ -854,7 +854,7 @@ std::string GenerateRandomString(int len) } char *str = new char[len]; for (int i = 0; i < len; i++) { - int index = rand() % (sizeof charSet - 1); + int index = rand() % (charSet.length() - 1); str[i] = charSet[index]; } std::string randomStr = str;