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
HTTPSocket.h@20:bbbfaf4cc055, 2016-11-08 (annotated)
- Committer:
- mapellil
- Date:
- Tue Nov 08 17:21:42 2016 +0000
- Revision:
- 20:bbbfaf4cc055
- Parent:
- 19:17578cfdb57a
fixed wind msg
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mapellil | 19:17578cfdb57a | 1 | #if !defined(HTTPSOCKET_H) |
| mapellil | 19:17578cfdb57a | 2 | #define HTTPSOCKET_H |
| mapellil | 19:17578cfdb57a | 3 | |
| mapellil | 19:17578cfdb57a | 4 | #include "mbed.h" |
| mapellil | 19:17578cfdb57a | 5 | #include "TCPSocket.h" |
| mapellil | 19:17578cfdb57a | 6 | |
| mapellil | 19:17578cfdb57a | 7 | class HTTPSocket |
| mapellil | 19:17578cfdb57a | 8 | { |
| mapellil | 19:17578cfdb57a | 9 | public: |
| mapellil | 19:17578cfdb57a | 10 | |
| mapellil | 19:17578cfdb57a | 11 | int open(NetworkStack *ipstack) |
| mapellil | 19:17578cfdb57a | 12 | { |
| mapellil | 19:17578cfdb57a | 13 | return mysock.open(ipstack); |
| mapellil | 19:17578cfdb57a | 14 | } |
| mapellil | 19:17578cfdb57a | 15 | |
| mapellil | 19:17578cfdb57a | 16 | int connect(char* hostname, int port, int timeout=1000) |
| mapellil | 19:17578cfdb57a | 17 | { |
| mapellil | 19:17578cfdb57a | 18 | int err; |
| mapellil | 19:17578cfdb57a | 19 | mysock.set_timeout(timeout); |
| mapellil | 19:17578cfdb57a | 20 | //SocketAddress addr(&spwf, hostname); |
| mapellil | 19:17578cfdb57a | 21 | // pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address()); |
| mapellil | 19:17578cfdb57a | 22 | |
| mapellil | 20:bbbfaf4cc055 | 23 | // printf ("TCP hostaname: %s, port: %d\n\r", hostname, port); |
| mapellil | 19:17578cfdb57a | 24 | err = mysock.connect(hostname, port); |
| mapellil | 19:17578cfdb57a | 25 | // t.start(); |
| mapellil | 19:17578cfdb57a | 26 | return err; |
| mapellil | 19:17578cfdb57a | 27 | } |
| mapellil | 19:17578cfdb57a | 28 | |
| mapellil | 19:17578cfdb57a | 29 | // int read(unsigned char* buffer, int len, int timeout) |
| mapellil | 19:17578cfdb57a | 30 | int recv(char* buffer, int len) |
| mapellil | 19:17578cfdb57a | 31 | { |
| mapellil | 19:17578cfdb57a | 32 | // mysock.set_timeout(timeout); |
| mapellil | 19:17578cfdb57a | 33 | //t.reset(); |
| mapellil | 19:17578cfdb57a | 34 | // int start = t.read_ms(); |
| mapellil | 19:17578cfdb57a | 35 | int rc = mysock.recv((char*)buffer, len); |
| mapellil | 19:17578cfdb57a | 36 | // int stop = t.read_ms(); |
| mapellil | 19:17578cfdb57a | 37 | // 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); |
| mapellil | 19:17578cfdb57a | 38 | return rc; |
| mapellil | 19:17578cfdb57a | 39 | } |
| mapellil | 19:17578cfdb57a | 40 | |
| mapellil | 19:17578cfdb57a | 41 | // int write(unsigned char* buffer, int len, int timeout) |
| mapellil | 19:17578cfdb57a | 42 | int send(char* buffer, int len) |
| mapellil | 19:17578cfdb57a | 43 | { |
| mapellil | 19:17578cfdb57a | 44 | // mysock.set_timeout(timeout); |
| mapellil | 19:17578cfdb57a | 45 | // mysock.set_blocking(false, timeout); |
| mapellil | 19:17578cfdb57a | 46 | // mysock.set_blocking(false); |
| mapellil | 19:17578cfdb57a | 47 | int rc = mysock.send((char*)buffer, len); |
| mapellil | 19:17578cfdb57a | 48 | // printf ("send File: %s, Line: %d Write nB: %d rc: %d\n\r",__FILE__,__LINE__, len, rc); |
| mapellil | 19:17578cfdb57a | 49 | return rc; |
| mapellil | 19:17578cfdb57a | 50 | } |
| mapellil | 19:17578cfdb57a | 51 | |
| mapellil | 19:17578cfdb57a | 52 | int set_blocking(bool mode) |
| mapellil | 19:17578cfdb57a | 53 | { |
| mapellil | 19:17578cfdb57a | 54 | mysock.set_blocking (mode); |
| mapellil | 19:17578cfdb57a | 55 | } |
| mapellil | 19:17578cfdb57a | 56 | |
| mapellil | 19:17578cfdb57a | 57 | |
| mapellil | 19:17578cfdb57a | 58 | // int disconnect() |
| mapellil | 19:17578cfdb57a | 59 | int close() |
| mapellil | 19:17578cfdb57a | 60 | { |
| mapellil | 19:17578cfdb57a | 61 | // t.stop(); |
| mapellil | 19:17578cfdb57a | 62 | return mysock.close(); |
| mapellil | 19:17578cfdb57a | 63 | } |
| mapellil | 19:17578cfdb57a | 64 | |
| mapellil | 19:17578cfdb57a | 65 | private: |
| mapellil | 19:17578cfdb57a | 66 | TCPSocket mysock; |
| mapellil | 19:17578cfdb57a | 67 | // Timer t; |
| mapellil | 19:17578cfdb57a | 68 | |
| mapellil | 19:17578cfdb57a | 69 | }; |
| mapellil | 19:17578cfdb57a | 70 | #endif |
