Hi astc
What is the server doing? If it is not sending messages, I could see where your test would break.
I modified our simple examples to do what you are trying to accomplish:
https://github.com/wolfSSL/wolfssl-exam … master/tls
diff --git a/tls/client-tls.c b/tls/client-tls.c
index d1e06be..9f13d84 100644
--- a/tls/client-tls.c
+++ b/tls/client-tls.c
@@ -133,32 +133,68 @@ int main(int argc, char** argv)
goto cleanup;
}
- /* Get a message for the server from stdin */
- printf("Message for server: ");
- memset(buff, 0, sizeof(buff));
- if (fgets(buff, sizeof(buff), stdin) == NULL) {
- fprintf(stderr, "ERROR: failed to get message for server\n");
- ret = -1;
- goto cleanup;
- }
- len = strnlen(buff, sizeof(buff));
-
- /* Send the message to the server */
- if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
- fprintf(stderr, "ERROR: failed to write entire message\n");
- fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
- goto cleanup;
+#if 1
+ while (1)
+ {
+ int err;
+ char stringtosend[1024];
+ char readBuf[1024];
+
+ printf("Send a string to the server\n"
+ "x to exit\n");
+ if (fgets(stringtosend, sizeof(stringtosend), stdin) == NULL) {
+ printf("error reading");
+ }
+ do {
+ ret = wolfSSL_write(ssl, stringtosend, sizeof(stringtosend));
+ err = wolfSSL_get_error(ssl, ret);
+ } while (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE);
+ printf("Sent (%d): %s\n", err, stringtosend);
+
+ XMEMSET(readBuf, 0, sizeof(readBuf));
+ do {
+ ret = wolfSSL_read(ssl, readBuf, sizeof(readBuf)-1);
+ err = wolfSSL_get_error(ssl, ret);
+ } while (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE);
+ printf("Read (%d): %s\n", err, readBuf);
+
+
+ //ssl->buffers.clearOutputBuffer.length = 0;
+ if (stringtosend[0] == 'x' && stringtosend[1] == '\n'){
+ break;
+ }
}
-
- /* Read the server data into our buff array */
- memset(buff, 0, sizeof(buff));
- if ((ret = wolfSSL_read(ssl, buff, sizeof(buff)-1)) == -1) {
- fprintf(stderr, "ERROR: failed to read\n");
- goto cleanup;
- }
-
- /* Print to stdout any data the server sends */
- printf("Server: %s\n", buff);
+#else
+ do {
+ /* Get a message for the server from stdin */
+ printf("Message for server: ");
+ memset(buff, 0, sizeof(buff));
+ if (fgets(buff, sizeof(buff), stdin) == NULL) {
+ fprintf(stderr, "ERROR: failed to get message for server\n");
+ ret = -1;
+ goto cleanup;
+ }
+ len = strnlen(buff, sizeof(buff));
+
+ /* Send the message to the server */
+ if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
+ fprintf(stderr, "ERROR: failed to write entire message\n");
+ fprintf(stderr, "%d bytes of %d bytes were sent", ret, (int) len);
+ goto cleanup;
+ }
+
+ /* Read the server data into our buff array */
+ memset(buff, 0, sizeof(buff));
+ if ((ret = wolfSSL_read(ssl, buff, sizeof(buff)-1)) == -1) {
+ fprintf(stderr, "ERROR: failed to read\n");
+ goto cleanup;
+ }
+
+ /* Print to stdout any data the server sends */
+ printf("Server: %s\n", buff);
+
+ } while(1);
+#endif
/* Bidirectional shutdown */
while (wolfSSL_shutdown(ssl) == SSL_SHUTDOWN_NOT_DONE) {
diff --git a/tls/server-tls.c b/tls/server-tls.c
index fa79a4d..6fc3c50 100644
--- a/tls/server-tls.c
+++ b/tls/server-tls.c
@@ -160,35 +160,35 @@ int main()
printf("Client connected successfully\n");
-
-
- /* Read the client data into our buff array */
- memset(buff, 0, sizeof(buff));
- if ((ret = wolfSSL_read(ssl, buff, sizeof(buff)-1)) == -1) {
- fprintf(stderr, "ERROR: failed to read\n");
- goto exit;
- }
-
- /* Print to stdout any data the client sends */
- printf("Client: %s\n", buff);
-
- /* Check for server shutdown command */
- if (strncmp(buff, "shutdown", 8) == 0) {
- printf("Shutdown command issued!\n");
- shutdown = 1;
- }
-
-
-
- /* Write our reply into buff */
- memset(buff, 0, sizeof(buff));
- memcpy(buff, reply, strlen(reply));
- len = strnlen(buff, sizeof(buff));
-
- /* Reply back to the client */
- if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
- fprintf(stderr, "ERROR: failed to write\n");
- goto exit;
+ while(!shutdown) {
+ /* Read the client data into our buff array */
+ memset(buff, 0, sizeof(buff));
+ if ((ret = wolfSSL_read(ssl, buff, sizeof(buff)-1)) == -1) {
+ fprintf(stderr, "ERROR: failed to read\n");
+ goto exit;
+ }
+
+ /* Print to stdout any data the client sends */
+ printf("Client: %s\n", buff);
+
+ /* Check for server shutdown command */
+ if (strncmp(buff, "shutdown", 8) == 0) {
+ printf("Shutdown command issued!\n");
+ shutdown = 1;
+ }
+
+
+
+ /* Write our reply into buff */
+ memset(buff, 0, sizeof(buff));
+ memcpy(buff, reply, strlen(reply));
+ len = strnlen(buff, sizeof(buff));
+
+ /* Reply back to the client */
+ if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
+ fprintf(stderr, "ERROR: failed to write\n");
+ goto exit;
+ }
}
/* Notify the client that the connection is ending */