This library is used to make HTTP and HTTPS calls from mbed OS 5 applications.
Fork of mbed-http by
Revision 12:530c2ebee349, committed 2017-03-28
- Comitter:
- Jan Jongboom
- Date:
- Tue Mar 28 14:47:51 2017 +0200
- Parent:
- 11:96e4dcb9c0c2
- Child:
- 13:992d953ecfb9
- Commit message:
- Update README for socket reuse
Changed in this revision
| README.md | Show annotated file Show diff for this revision Revisions of this file |
--- a/README.md Tue Mar 28 14:44:39 2017 +0200
+++ b/README.md Tue Mar 28 14:47:51 2017 +0200
@@ -54,6 +54,39 @@
req->send(NULL, 0, body_callback);
```
+## Socket re-use
+
+By default the library opens a new socket per request. This is wasteful, especially when dealing with TLS requests. You can re-use sockets like this:
+
+### HTTP
+
+```cpp
+TCPSocket* socket = new TCPSocket();
+
+nsapi_error_t open_result = socket->open(network);
+// check open_result
+
+nsapi_error_t connect_result = socket->connect("httpbin.org", 80);
+// check connect_result
+
+// Pass in `socket`, instead of `network` as first argument
+HttpRequest* req = new HttpRequest(socket, HTTP_GET, "http://httpbin.org/status/418");
+```
+
+### HTTPS
+
+```cpp
+TLSSocket* socket = new TLSSocket(network, "httpbin.org", 443, SSL_CA_PEM);
+socket->set_debug(true);
+if (socket->connect() != 0) {
+ printf("TLS Connect failed %d\n", socket->error());
+ return 1;
+}
+
+// Pass in `socket`, instead of `network` as first argument, and omit the `SSL_CA_PEM` argument
+HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418");
+```
+
## Tested on
* K64F with Ethernet.
