Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HTTPClient_HelloWorld_IDW01M1 wifigianluigi HTTPClient_HelloWorld_IDW01M1_Fabio_Ricezione
Fork of HTTPClient by
Diff: HTTPSocket.h
- Revision:
- 19:17578cfdb57a
- Child:
- 20:bbbfaf4cc055
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPSocket.h Mon Nov 07 17:08:02 2016 +0000
@@ -0,0 +1,70 @@
+#if !defined(HTTPSOCKET_H)
+#define HTTPSOCKET_H
+
+#include "mbed.h"
+#include "TCPSocket.h"
+
+class HTTPSocket
+{
+public:
+
+ int open(NetworkStack *ipstack)
+ {
+ return mysock.open(ipstack);
+ }
+
+ int connect(char* hostname, int port, int timeout=1000)
+ {
+ int err;
+ mysock.set_timeout(timeout);
+//SocketAddress addr(&spwf, hostname);
+// pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());
+
+ printf ("TCP hostaname: %s, port: %d\n\r", hostname, port);
+ err = mysock.connect(hostname, port);
+// t.start();
+ return err;
+ }
+
+// int read(unsigned char* buffer, int len, int timeout)
+ int recv(char* buffer, int len)
+ {
+// mysock.set_timeout(timeout);
+//t.reset();
+// int start = t.read_ms();
+ int rc = mysock.recv((char*)buffer, len);
+// int stop = t.read_ms();
+// if (rc>0) printf ("recv File: %s, Line: %d Read nB: %d rc: %d timeout: %d elaps: %d\n\r",__FILE__,__LINE__, len, rc, timeout, stop-start);
+ return rc;
+ }
+
+// int write(unsigned char* buffer, int len, int timeout)
+ int send(char* buffer, int len)
+ {
+// mysock.set_timeout(timeout);
+// mysock.set_blocking(false, timeout);
+// mysock.set_blocking(false);
+ int rc = mysock.send((char*)buffer, len);
+// printf ("send File: %s, Line: %d Write nB: %d rc: %d\n\r",__FILE__,__LINE__, len, rc);
+ return rc;
+ }
+
+ int set_blocking(bool mode)
+ {
+ mysock.set_blocking (mode);
+ }
+
+
+// int disconnect()
+ int close()
+ {
+// t.stop();
+ return mysock.close();
+ }
+
+private:
+ TCPSocket mysock;
+ // Timer t;
+
+};
+#endif
